Struts2 HelloWorld

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


七、访问流程




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值