<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    zhyiwww
    用平實的筆,記錄編程路上的點點滴滴………
    posts - 536,comments - 394,trackbacks - 0

    解決開發中多用戶修改消息,或者多用戶修改配置文件的沖突問題。
    注意在粗體部分實現一次將所有的配置資源文件都讀取到內存中去。任何一個用戶只需要自己舔加自己的配置文件就可以了。
    最后統一在實現配置文件的整合。


    寫一個BaseHttpServlet:

    package base.servlet;

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FilenameFilter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.net.URL;
    import java.util.List;
    import java.util.Properties;

    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.log4j.Logger;

    /**
     * Servlet implementation class CcxHttpServlet
     */
    public class BaseHttpServlet extends HttpServlet {

        /**
         *
         */
        private static final long serialVersionUID = -5793303331880998441L;

        protected Logger log = Logger.getLogger(this.getClass());

        private final String MESSAGE_RESOURCE_FILE = "/com/xxx/project/i18/message.properties";
       
        protected final static Properties messages = new Properties();
       
       
        static{
                // TODO you need change according to different project
                String messageDir = "/com/ccx/information/i18";
               
                URL url = BaseHttpServlet.class.getResource(messageDir);
               
                File mf = new File(url.getFile());
               
                if(mf.isDirectory()){
                    File[] l = mf.listFiles(new FilenameFilter(){
                        public boolean accept(File dir, String name) {
                            return name.endsWith(".properties");
                        }   
                    });
                   
                   
                    for(int i=0;i<l.length;i++){
                        File f = l[i];
                        try {
                            messages.load(new FileInputStream(f));
                        } catch (FileNotFoundException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                   
                }
        }

       
        /**
         * @see HttpServlet#HttpServlet()
         */
        public BaseHttpServlet() {
            super();
        }

        /**
         * forword to page
         *
         * @param request
         * @param response
         * @param uri
         *            ,the target page
         * @throws ServletException
         * @throws IOException
         */
        protected void farward(HttpServletRequest request,
                HttpServletResponse response, String uri) throws ServletException,
                IOException {
            RequestDispatcher dis = request.getRequestDispatcher(uri);
            if (dis == null) {
                // to error page
                output(response, "error : no page found");
            } else {
                dis.forward(request, response);
            }
        }

        /**
         * print information to client
         *
         * @param response
         * @param notice
         * @throws IOException
         */
        protected void output(HttpServletResponse response, String notice)
                throws IOException {
            response.setContentType("text/html");
            response.setCharacterEncoding("UTF-8");
           
            PrintWriter out = response.getWriter();
            out.print("<span style=\"color:red\">");
            out.println(notice);
            out.print("</span>");
            out.flush();
            out.close();
        }

        /**
         * send redirect to target page
         *
         * @param response
         * @param uri
         * @throws ServletException
         * @throws IOException
         */
        protected void redirect(HttpServletResponse response, String uri)
                throws ServletException, IOException {
            response.sendRedirect(uri);
        }

        public void init() throws ServletException {
            super.init();
           

           
        }

       
       
       
    }






    |----------------------------------------------------------------------------------------|
                               版權聲明  版權所有 @zhyiwww
                引用請注明來源 http://m.tkk7.com/zhyiwww   
    |----------------------------------------------------------------------------------------|
    posted on 2010-03-20 18:20 zhyiwww 閱讀(422) 評論(0)  編輯  收藏 所屬分類: j2ee
    主站蜘蛛池模板: 国产一级淫片视频免费看| 91手机看片国产永久免费| 日本媚薬痉挛在线观看免费| 666精品国产精品亚洲| 久久精品国产大片免费观看| 亚洲中文字幕日产乱码高清app | 久久精品免费大片国产大片| 亚洲男女内射在线播放| 亚洲天堂免费在线视频| 亚洲精品无码久久久久去q| 国产又黄又爽胸又大免费视频| 在线亚洲精品福利网址导航| 国产真人无码作爱免费视频| 亚洲AV本道一区二区三区四区 | 亚洲av无码一区二区三区天堂| 看全色黄大色大片免费久久| 亚洲Av永久无码精品一区二区| 国产大片91精品免费观看男同| 五级黄18以上免费看| 夜夜春亚洲嫩草影院| 99久久国产免费-99久久国产免费| 亚洲制服丝袜精品久久| 日本无吗免费一二区| yellow免费网站| 国产成人亚洲综合无码精品| 最近中文字幕mv免费高清视频8| 亚洲国产人成在线观看| 免费看美女让人桶尿口| 污视频网站免费在线观看| 亚洲人成人无码网www电影首页| 十九岁在线观看免费完整版电影| 亚洲一区二区三区深夜天堂| 国产男女性潮高清免费网站| 中文字幕版免费电影网站| 亚洲精品中文字幕乱码影院| 热99re久久精品精品免费| 国产免费A∨在线播放| 亚洲人成在线中文字幕| www国产亚洲精品久久久| 99re视频精品全部免费| 男性gay黄免费网站|