<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://www.tkk7.com/zhyiwww   
    |----------------------------------------------------------------------------------------|
    posted on 2010-03-20 18:20 zhyiwww 閱讀(422) 評論(0)  編輯  收藏 所屬分類: j2ee
    主站蜘蛛池模板: 亚洲av日韩av激情亚洲| 亚洲国产精品无码成人片久久| 亚洲大尺码专区影院| 久久黄色免费网站| 亚洲日本精品一区二区| 亚洲精品在线免费观看| 亚洲国产美女福利直播秀一区二区| 中文免费观看视频网站| 亚洲色大情网站www| 日本免费高清一本视频| 黄色a级免费网站| 亚洲午夜国产精品无码| 精品四虎免费观看国产高清午夜| 亚洲午夜精品久久久久久人妖| 91免费福利精品国产| 亚洲精品亚洲人成在线播放| 天天摸天天碰成人免费视频| 国产精品亚洲专区无码不卡| 国产成人精品亚洲精品| 免费福利在线视频| 亚洲一欧洲中文字幕在线| 日韩成人在线免费视频| 2022免费国产精品福利在线| 亚洲国产精品无码久久一区二区| 2020因为爱你带字幕免费观看全集 | 亚洲精品无码久久久| 一级一黄在线观看视频免费| 久久精品国产96精品亚洲| 四虎永久在线精品免费观看视频| 亚洲视频免费播放| 女人18毛片特级一级免费视频| 九九久久精品国产免费看小说| 亚洲AV福利天堂一区二区三| 国产精品无码免费播放| eeuss免费天堂影院| 亚洲丝袜中文字幕| 亚洲一区二区三区在线观看精品中文| 亚洲视频在线免费看| 黄网站色视频免费看无下截| 久久久久亚洲av无码尤物| 韩国免费三片在线视频|