流程
请求-处理-响应
struts
1.导价包
2.设置过滤器
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3.构建action类继承ActionSupport
4.设置struts.xml文件
<package name="default" namespace="/" extends="struts-default">
<action name="hello" class="com.action.UserAction" method="execute"> <!--action为地址和action的关系 -->
<result name="success">welcome.jsp</result>
<!--result是返回的结果 -->
</action>
</package>
默认
<action class="com.opensymphony.xwork2.ActionSupport" method="execute">
<result name="success" type="dispatcher"></result>
</action>
Action接收参数的三种方式
作用:收集数据;
(1)属性方式 对属性进行封装 username
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
(2)javaBean方式 对实体类进行封装 user.username
private User user=new User();
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
(2)ModelDriven方式 实现接口 username
@Override
public User getModel() {
return user;
}
(4)action上下文:ServletActionContext
HttpServletRequest request = ServletActionContext.getRequest();
String ename = request.getParameter("ename");