您的位置:首页 > 编程语言 > Java开发

Struts2 HelloWorld

2016-02-20 20:23 204 查看
一、在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" />
问题解决。

七、访问流程

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: