struts1.2总结

struts1.2的基本流程:
1、ActionServlet接收客户端的HTTP请求,使用ActionForm自动接收请求表单信息,然后将请求分发给相应的Action对象
2、Action对象调用execute()方法处理请求,此时可以使用先前的ActionForm,也可调用其他的JavaBean实现业务逻辑。然后返回ActionForward对象给ActionServlet
3、根据ActionForward对象封装的信息,ActionServlet将HTTP请求再次转发给其他页面,最终发送响应会客户端ActionServlet中央控制器
ActionServlet负责处理所有的Struts请求 .do请求
ActionServlet是自动被调用的
ActionServlet会自动读取Struts-config.xml配置文件,并驱动相关的处理
ActionServlet的映射是可变的,.do的映射是可变的ActionForm属性和页面是相互关联的
ActionForm可以实现类型的自动转
form必须继承必须继承ActionForm
通过ActionForm的get方法我们可以再Action类中通过getUsername()\getPasswd()来得到参数值Struts中提供了两种转向方式:
1).使用Struts-config.xml文件中的forward配置
<forward name="index" path="/index.jsp" redirect="true"></forward>2).ActionForward的方式,其包括有两种
A、request.getRequestDispatcher().forward()B、return new ActionForward("/index.jsp");
注意:如果要以response.sendRedirect()方式来转向,必须使用:
return new ActionForward("/index.jsp",true); struts1.2标签:
1、在使用标签是需要引用:
A、默认导入方式
   <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
   <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
B、在web.xml配置中设置
   <jsp-config>
    <taglib>
     <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
     <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
    </taglib>
    <taglib>
     <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
     <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
    </taglib>
   </jsp-config>2、bean标签
A、<bean:define id="myid" value="superjunior"></bean:define>${myid }
B、<bean:write name="myid" scope="application"/>
   <html:submit value="${myid}"/><html:cancel/>
C、<%
request.setAttribute("ename","SMITH");
Emp e = new Emp();
e.setEmpno("7556");
e.setEname("ALLEN");
e.setJob("MANAGER");
request.setAttribute("e",e);
   %>
   <bean:write name="e" property="job"/>3、logic逻辑标签
A、logic:present 判断某个元素是否存在的标签
<%
request.setAttribute("username","zhangshanfeng");
%>
<logic:present name="username">
username这个值有,值为<bean:write name="username"/>
</logic:present>
<logic:notPresent name="username">username这个真没有</logic:notPresent>B、logic:equal-精确查询 跟 logic:match-是否匹配某个值,相当于模糊查询
<%
request.setAttribute("username","superjunior");
%>
<logic:equal name="username" value="superjunior">equal正确</logic:equal><br>
<logic:match name="username" value="erjun">match正确相当于模糊查询</logic:match>C、html:form 注意:要在配置文件中定义全局Forward;表单标签,action的值和struts-config。xml文件存在着对应关系
<html:form action="/login">
<logic:forward name="index"/>
</html:form>D、logic:iterate
<%
List list = new ArrayList();
list.add("superjunior");
list.add("14");
list.add("elf");
request.setAttribute("list",list);
%>
<logic:iterate id="i" name="list">
<bean:write name="i"/><br/>
</logic:iterate>E、html标签:对于所有的form内的控件,比如text,checkbox,passwd等,javascript事件和常用属性同样有效
列举几种:
hobby :
<html:multibox property="hobby" value="a" />听歌
<html:multibox property="hobby" value="b" />读书
<html:multibox property="hobby" value="c" />上网<br>
   
classroom :
<html:select property="classroom">
<html:option value="aa">应用一班</html:option>
<html:option value="bb">应用二班</html:option>
<html:option value="cc">应用三班</html:option>
</html:select><br/>
sex :
<html:radio property="sex" value="female"/>女
<html:radio property="sex" value="male"/>男<br/>
<html:submit/><html:cancel/>注意:html:multibox多选框
ActionServlet在处理页面值的提取的时候,对Multibox会采用
request.getParameterValues()这种方式。所以,在formbean类中的,和multibox对应的属性,必须

为数组类型

转自:http://www.talentdigger.cn/home/space-3342-do-blog-id-22320.html

原文地址:https://www.cnblogs.com/xinzhuangzi/p/4100498.html