打开自己的MyEclipse,新建一个普通的javaweb项目,如图所示:
Struts2项目搭建的过程
2.视图层 jsp页面,如下图:
Struts2项目搭建的过程
register.jsp代码如下:

用户名:
性别:

index.jsp代码如下:

用户名:${requestScope.name }
性别:${requestScope.sex}

3.新建一个控制层 RegisterAction 类,如下图:
Struts2项目搭建的过程
代码如下:

public class RegisterAction {
private String name;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String struts(){
return “success”;
}
}
4.在web-inf 下的lib 里边添加Struts2所需要的jar包,如下图:
Struts2项目搭建的过程
5.在web.xml中配置Struts2的过滤器,代码如下:

This is the description of my J2EE component This is the display name of my J2EE component TestServlet com.hnpi.controller.TestServlet TestServlet /TestServlet struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 /* 6.在src下新建一个请求分发的配置文件 struts.xml,如下图:![在这里插入图片描述](https://img-blog.csdnimg.cn/20181031202023429.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNTcxMDAx,size_16,color_FFFFFF,t_70)

代码如下:

/index.jsp

以上内容仅供参考,如有内容错误,请留言讨论。

相关文章: