一、在struts的官网下载最新的struts(http://struts.apache.org/),实在不会百度如何下载struts2。
二、在src目录下配置struts.xml配置文件,并在lib下添加struts相应的类库。
<pre name="code" class="html" style="font-size: 18px;"><struts>
<package name="default" namespace="/" extends="struts-default">
<action name="hello">
<result>
/Hello.jsp
</result>
</action>
</package>
</struts>
三、配置web.xml,添加过滤器。
<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>
四、编写Hello.jsp页面
<body>
Hello Struts2 <br>
</body>
五、启动tomcat服务器,访问http://localhost:8888/Struts2_Introduction/hello.action
或者http://localhost:8888/Struts2_Introduction/hello
六、浏览器显示:Hello Struts2
注意:使用以上配置,当修改struts.xml中action name 以后,必须重启服务器才能访问到jsp页面。
或者在struts.xml中加入一句:
<constant name="struts.devMode" value="true" />
问题解决。
七、访问流程