一、在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" />问题解决。
七、访问流程

本文详细介绍Struts2框架的安装配置步骤,包括从官方网站下载最新版本的Struts2、在项目中配置struts.xml文件及添加所需类库、设置web.xml中的过滤器等关键环节。同时提供了一个简单的示例,通过创建Hello.jsp页面并访问,演示了如何成功展示HelloStruts2。文章还指出,在修改struts.xml文件后需重启服务器才能生效的问题,并提供了开启开发模式的解决方案。
5807

被折叠的 条评论
为什么被折叠?



