structs2下的第一个helloworld!

下载安装好structs2
1.创建并配置好web应用程序,使支持structs2:
将structs2/lib下的jar文件除了Junit,sprint-test.jar都拷贝到web-inf/lib下面

2.配置web应用的web.xml文件。拦截所有url,使用struct2
<?xml version="1.0" encoding="GBK"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

	<!-- 定义Struts2的核心Filter -->
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
	</filter>
	<!-- 让Struts2的核心Filter拦截所有请求 -->
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>



3.创建一个hello.jsp ,在里面输入helloworld!

4.在src目录下创建一个structs.xml,配置struts下跳转到hello.jsp

<?xml version="1.0" encoding="GBK"?>

<!DOCTYPE struts SYSTEM "http://struts.apache.org/dtds/struts-2.1.7.dtd" PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN">

<!-- 指定Struts 2配置文件的根元素 -->
-<struts> 
<!-- 指定全局国际化资源文件 -->
 <constant value="mess" name="struts.custom.i18n.resources"/> 
<!-- 指定国际化编码所使用的字符集 -->
 <constant value="GBK" name="struts.i18n.encoding"/> 
<!-- 所有的Action定义都应该放在package下 -->
<package name="default" extends="struts-default">
<action name="hello" class=""> 
<!-- 定义逻辑视图和物理资源之间的映射 -->
 <result name="input">/hello.jsp</result> 
</action> 
</package> 
</struts>




好了,这样在浏览器中输入:localhost:8080/web项目名称/hello
就可以看到helloworld!了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值