日期:2014-05-20 浏览次数:20826 次
web.services.members.response.msg.notfound=\u5bf9\u4e0d\u8d77\uff0c\u6ca1\u6709\u53d1\u73b0\u4e0e[${username}]\u76f8\u5339\u914d\u7528\u6237\uff01 web.services.members.response.msg.found=\u5171\u627e\u5230\u4e0e[${username}]\u76f8\u5339\u914d\u7684\u7528\u6237${count}\u4e2a\uff01 web.services.members.response.msg.exception=\u670d\u52a1\u5668\u51fa\u73b0\u5f02\u5e38\uff0c\u8bf7\u7a0d\u540e\u518d\u8bd5\uff01 web.services.members.response.msg.error=\u670d\u52a1\u5668\u51fa\u73b0\u5185\u90e8\u9519\u8bef\uff01
package com.dongantech.eshop.web.util; import java.util.*; import java.io.*; public class MessageBundle { public static Properties PROPS = null ; private Map bundle = null; static { InputStream propertiesInputStream = MessageBundle.class.getResourceAsStream("/messages.properties"); PROPS = new Properties(); try { PROPS.load(propertiesInputStream); } catch (IOException e) { e.printStackTrace(); } } public MessageBundle(){ bundle = new HashMap(); } public void setBundle(Map theBundle){ bundle = theBundle; } public Map getBundle(){ return bundle ; } public String getMessage(String theMsgKey){ return (String)bundle.get(theMsgKey); } public void putIntoBundle(String theMsgKey){ String msgFrame = MessageBundle.PROPS.getProperty(theMsgKey); bundle.put(theMsgKey,msgFrame); } }
public class MemberManagerServlet extends HttpServlet{ public static final String MSG_KEY_NOT_FOUND = "web.services.members.response.msg.notfound" ; public static final String MSG_KEY_FOUND = "web.services.members.response.msg.found" ; public static final String MSG_KEY_EXCEPTION = "web.services.members.response.msg.exception" ; public static final String MSG_KEY_ERROR = "web.services.members.response.msg.error" ; private Map requestHandlers = null ; private PageLocator pageLocator = null ; private MessageBundle messageBundle = null ; public MemberManagerServlet(){ requestHandlers = new HashMap(); pageLocator = new PageLocator(); pageLocator.registerPage(SimpleResponse.TYPE_FOUND,MemberManagerServlet.PAGE_FOUND ); pageLocator.registerPage(SimpleResponse.TYPE_NOT_FOUND,MemberManagerServlet.PAGE_NOT_FOUND); pageLocator.registerPage(SimpleResponse.TYPE_EXCEPTION,MemberManagerServlet.PAGE_EXCEPTION); pageLocator.registerPage(SimpleResponse.TYPE_ERROR,MemberManagerServlet.PAGE_ERROR); messageBundle.putIntoBundle(MemberManagerServlet.MSG_KEY_NOT_FOUND); messageBundle.putIntoBundle(MemberManagerServlet.MSG_KEY_FOUND); messageBundle.putIntoBundle(MemberManagerServlet.MSG_KEY_EXCEPTION); messageBundle.putIntoBundle(MemberManagerServlet.MSG_KEY_ERROR); } public void init(ServletConfig config){ try { super.init(config); } catch (ServletException e) { e.printStackTrace(); } } public void doGet(HttpServletRequest httpReq,HttpServletResponse httpResp){ Response response = processRequest(httpReq,httpResp); try { deliver(response); } catch (Exception e) { e.printStackTrace(); } } public void doPost(HttpServletRequest httpReq,HttpServletResponse httpResp){ Response response = processRequest(httpReq,httpResp); try { deliver(response); } catch (Exception e) { e.printStackTrace(); } } public Response processRequest(HttpServletRequest httpReq,HttpServletResponse httpResp){ Response response = null ; String handlerName = httpReq.getParameter("request"); RequestHandler handler = getHandler(handlerName); Request request = buildRequest(httpReq); try { response = handler.process(request); response.getContext().put("page",getPage(response.getType())); } catch (Exception e) { response = new SimpleResponse(SimpleResponse.TYPE_ERROR); e.printStackTrace(); } return response ; } }