阅读582 返回首页    go 阿里云 go 技术社区[云栖]


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="https://www.w3.org/2001/XMLSchema-instance" xmlns="https://java.sun.com/xml/ns/javaee" xmlns:web="https://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="https://java.sun.com/xml/ns/javaee https://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  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 "https://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" > 
<!-- 定义逻辑视图和物理资源之间的映射 -->
 <result name="input">/hello.jsp</result> 
</action> 
</package> 
</struts>




好了,这样在浏览器中输入:localhost:8080/web项目名称/hello
就可以看到helloworld!了。

最后更新:2017-04-02 17:09:28

  上一篇:go 使用WAMP进行压力测试,等到TOMCAT报错发现问题,基本解决国航OA服务器慢慢死掉的问题
  下一篇:go 《iPhone与iPad开发实战—iOS经典应用剖析》连载四