一、开发环境搭建java
1.一、导入相应的jar包(能够参考blank项目)web
1.二、设置web.xml开启Struts2的过滤器apache
<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>
1.三、建立相应的action浏览器
对于Struts2而言,action不用继承任何类均可以。app
public class HelloAction { //写一个execute()的方法,而且返回一个字符串 public String execute() { System.out.println("hello struts"); return "success"; } }
1.四、编写struts.xml文件(在类路径中建立struts.xml)jsp
<struts> <!-- extends="struts-default":必需要设置这个属性 --> <package name="default" namespace="/" extends="struts-default"> <!-- name="hello":在浏览器中访问的名称 class="org.pm.struts.action.HelloAction":编写action的类的完整路径 --> <action name="hello" class="org.pm.struts.action.HelloAction"> <!-- 当execute()方法返回的字符串是success的时候,所对应的视图是hello.jsp --> <result name="success">/hello.jsp</result> </action> </package> </struts>