structs2下的第一个helloworld!

简介: <span style="font-family:微软雅黑; font-size:18px">下载安装好structs2</span> <div style="font-family:微软雅黑; font-size:18px">1.创建并配置好web应用程序,使支持structs2:</div> <div style="font-family:微软雅黑; font-size:18px"
下载安装好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!了。
目录
相关文章
|
6月前
|
存储 Java 编译器
数组的定义与使用【JavaSE】
数组的定义与使用【JavaSE】
22 0
|
2月前
|
编译器 C++ 开发者
【C/C++】C/C++编程——第一个 C++ 程序:HelloWorld
【C/C++】C/C++编程——第一个 C++ 程序:HelloWorld
23 0
|
7月前
|
存储 机器学习/深度学习 Java
【javaSE】 数组的定义与使用
【javaSE】 数组的定义与使用
|
4月前
|
存储 机器学习/深度学习 Java
【JavaSE】数组的定义与使用
【JavaSE】数组的定义与使用
|
7月前
|
监控 Java
|
存储
编写一个应用程序,在主类Test1类中,创建两个链表List&lt;E&gt;对象,分别存储通过键盘输入的字符串内容
编写一个应用程序,在主类Test1类中,创建两个链表List&lt;E&gt;对象,分别存储通过键盘输入的字符串内容
52 0
|
JSON 开发工具 数据格式
CommonAPI使用例子-HelloWorld
CommonAPI使用例子-HelloWorld
CommonAPI使用例子-HelloWorld
|
C++
c++ demo3 结构体01
c++ demo3 结构体01
39 0
|
Java 开发工具 Windows
三、实现第一个HelloWorld
基于springboot框架实现第一个HelloWorld
62 0
三、实现第一个HelloWorld
|
Java 编译器 Go
Golang 笔记(一):值方法和指针方法(Value Methods vs Pointer Methods)
Golang 笔记(一):值方法和指针方法(Value Methods vs Pointer Methods)
126 0