1. 创建项目



2. 创建好之后的项目结构
-
添加依赖
Snip20180907_6.png
-
创建文件夹

-
设置文件夹类型
Snip20180907_8.png
指定java文件夹的类型为Sources
指定resources文件夹类型为Resources


3. 书写项目
CustomerAction
public class CustomerAction extends ActionSupport {
private Long custId;
public Long getCustId() {
return custId;
}
public void setCustId(Long custId) {
this.custId = custId;
}
public String findCustomerById(){
System.out.println("前端传过来的客户id是:"+custId);
return SUCCESS;
}
}
struts.xml
<struts>
<package name="customer" namespace="/" extends="struts-default">
<action name="CustomerAction" class="web.CustomerAction" method="findCustomerById">
<result name="success">/info.jsp</result>
</action>
</package>
</struts>
web.xml
<web-app>
<display-name>Archetype Created Web Application</display-name>
<!--引入核心过滤器-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
最后在浏览器进行请求就可以了
-
最后的项目结构
Snip20180907_12.png
网友评论