1.1自定义框架总结

1.1版本的自定义框架

首先在Hibernate的基础下,将多个Servlet合并成了一个ServletAction,此时ServletAction只负责做判断调用对应的Action类,Action类则负责从jsp页面拿值处理调用Biz,并返回调用的下一个jsp页面给ServletAction做出对应的处理.

 

以登录为例子

ServletAction

public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=gbk");
		String path=request.getRequestURI();
		String actionName=path.substring(path.lastIndexOf("/")+1,path.lastIndexOf("."));
		Action action=null;
		if(actionName.equals("login")){
			action=new LoginAction();
		}
		String resultView=action.execute(request, response);
		request.getRequestDispatcher(resultView).forward(request, response);
	}

 LoginAction

public String execute(HttpServletRequest request,
			HttpServletResponse response) {
		String uname=request.getParameter("uname");
		String upass=request.getParameter("upass");
		Info u=new Info();
		u.setUname(uname);
		u.setUpass(upass);
		UserBiz userBiz=new UserBizImpl();
		Info user=userBiz.findUser(u);
		if(user!=null){
			return "show.jsp";
		}else{
			request.setAttribute("msg", "用户名密码错误!");
			return "index.jsp";
		}
	}

 对应的jsp页面代码则是

<body>
    ${msg }
    <form name="f1" id="f1" action="login.cc" method="post">
      <table border="0">
        <tr>
          <td>Login:</td>
          <td><input type="text" name="uname" id="login"></td>
        </tr>
        <tr>
          <td>Password:</td>
          <td><input type="password" name="upass" id="password"></td>
        </tr> 
        <tr>
          <td colspan="2" align="center"><input type="submit" value="login user"></td>
        </tr>
      </table>
    </form>
  </body>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值