首页 > 代码库 > Library学习日志(……)
Library学习日志(……)
添加Library在buildpath中,就是右键工程->properties->java buildpath->Libraries
然后点击add Library就是添加Library 根据提示添加即可,
向已有Library中添加jar,添加内部的点击add jar;添加外部的点击add External JARS;
在一个Web应用中表单form的生命周期:
以登录所用的登录表单为例介绍:
login.jsp:<form name="form1" method="post" action="manager.do?action=login">
<servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> <init-param> <param-name>config</param-name> <param-value>/WEB-INF/struts-config.xml</param-value> </init-param> <init-param> <param-name>debug</param-name> <param-value>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping>
以上是Web.xml
structs-config.xml:
<action name="managerForm" path="/manager" scope="request" type="com.action.Manager" validate="true"> <forward name="managerQuery" path="/manager.jsp" /> <forward name="managerLoginok" path="/main.jsp" /> <forward name="managerAdd" path="/manager_ok.jsp?para=1" /> <forward name="managerQueryModify" path="/manager_Modify.jsp" />
Manager.java:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { String action = request.getParameter("action"); System.out.println("获取的查询字符串:" + action); if (action == null || "".equals(action)) { /*如果没有操作的动作*/ return mapping.findForward("error"); } else if ("login".equals(action)) { /*如果是处理管理员登陆*/ return managerLogin(mapping, form, request, response); } else if ("managerAdd".equals(action)) { return managerAdd(mapping, form, request, response); } else if ("managerQuery".equals(action)) { return managerQuery(mapping, form, request, response); } else if ("managerModifyQuery".equals(action)) { return managerModifyQuery(mapping, form, request, response); } else if ("managerModify".equals(action)) { return managerModify(mapping, form, request, response); } else if ("managerDel".equals(action)) { return managerDel(mapping, form, request, response); } else if ("querypwd".equals(action)) { return pwdQuery(mapping, form, request, response); } else if ("modifypwd".equals(action)) { return modifypwd(mapping, form, request, response); } request.setAttribute("error", "操作失败!"); return mapping.findForward("error"); }public ActionForward managerLogin(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { ManagerForm managerForm = (ManagerForm) form; managerForm.setName(managerForm.getName()); managerForm.setPwd(managerForm.getPwd()); /*将存有管理员信息的formbean传递给DAO业务层处理(查询是否存在该管理员帐号和密码)*/ int ret = managerDAO.checkManager(managerForm); System.out.print("验证结果ret的值:" + ret); /*业务层如果返回1,表示验证成功*/ if (ret == 1) { /*将用户帐号保存在session中*/ HttpSession session = request.getSession(); session.setAttribute("manager", managerForm.getName()); /*交给控制器,跳转到登陆成功的页面*/ return mapping.findForward("managerLoginok"); } else { request.setAttribute("error", "您输入的管理员名称或密码错误!"); return mapping.findForward("error"); } }
具体的处理就是以上这些内容,form的传递以及request的整个处理过程。
至于让人费解的这一个action的内容
<form name="form1" method="post" action="manager.do?action=login">
可以用一下这张图来解释:
Library学习日志(……)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。