【Structs2】Struts2入门之hello world程序的跑通
2012-09-04 21:08
465 查看
1.去官网下载Struts2.3.4.1的包,总大小约62M,用迅雷下载速度很快。
2.解压后如下图所示:
3.在eclipse中新建动态网页project。点击上图中apps,解压struts2-blank,依次在struts-2.3.4.1\apps\struts2-blank\WEB-INF\classes下找到struts.xml拷贝至eclipse工程的src目录下。
4.将 struts-2.3.4.1\apps\struts2-blank\WEB-INF\ 下的web.xml打开,拷贝(如下)代码至eclipse工程的web.xml中。
eclipse中web.xml如下:
5.拷贝struts-2.3.4.1\lib下部分jar包至eclipse工程的lib目录下,具体拷贝哪些jar包,参见下图。
6.将struts.xml改为如下:
6.新建Hello.jsp,部署好tomcat,启动服务后,在浏览器输入:
http://localhost:8080/Struts2_0100_Introduction/hello.action
即可正确访问。结果为:
2.解压后如下图所示:
3.在eclipse中新建动态网页project。点击上图中apps,解压struts2-blank,依次在struts-2.3.4.1\apps\struts2-blank\WEB-INF\classes下找到struts.xml拷贝至eclipse工程的src目录下。
4.将 struts-2.3.4.1\apps\struts2-blank\WEB-INF\ 下的web.xml打开,拷贝(如下)代码至eclipse工程的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>
eclipse中web.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>Struts2_0100_Introduction</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <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> </web-app>
5.拷贝struts-2.3.4.1\lib下部分jar包至eclipse工程的lib目录下,具体拷贝哪些jar包,参见下图。
6.将struts.xml改为如下:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <!-- <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index" /> <global-results> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping exception="java.lang.Exception" result="error"/> </global-exception-mappings> <action name="index"> <result type="redirectAction"> <param name="actionName">HelloWorld</param> <param name="namespace">/example</param> </result> </action> </package> <include file="example.xml"/> --> <!-- Add packages here --> <package name="default" namespace="/" extends="struts-default"> <action name="hello"> <result > /Hello.jsp </result> </action> </package> </struts>
6.新建Hello.jsp,部署好tomcat,启动服务后,在浏览器输入:
http://localhost:8080/Struts2_0100_Introduction/hello.action
即可正确访问。结果为:
相关文章推荐
- Struts2入门(1)-第一个Struts2程序
- C++ 入门教程(三) Hello World 程序讲解
- 【Java mail 入门教程】第二讲 hello world 入门程序(发送邮件)
- duilib入门简明教程 -- 第一个程序 Hello World(3) (转)
- JNI程序开发入门之高端大气上档次的Hello World
- 【Java mail 入门教程】第二讲 hello world 入门程序(发送邮件)
- Rexsee入门视频:在线创建Android应用Hello World程序
- 清华大学计算中心培训部-技术分享:java入门教程:Hello world程序
- 你的Java入门了么?看看程序一(Hello world)
- struts2的入门程序
- .net程序破解入门(ildasm) 之hello world
- 【RabbitMQ】RabbitMQ入门程序——Hello World
- NDK入门(一) 在Android Studio中创建并运行第一个ndk程序hello world
- struts2的入门程序
- node.js入门(二) 第一个程序 Hello World
- java入门的第一个程序代码 hello world
- OPENGL的入门第一个程序——Hello World
- [原]java专业程序代写(qq:928900200),学习笔记之基础入门<Struts2_实战演练(中)>(三十九)
- 【python】python入门篇:python安装和环境配置、pycharm安装、第一个python程序hello world
- duilib入门简明教程 -- 第一个程序 Hello World(3)