struts2框架的第一个hello world程序
2011-02-27 23:40
393 查看
先记下基本步骤吧,中间遇到很多莫名其妙的问题:
步骤:
1.创建web项目
2.导入struts2的jar包,我新建了一个用户库,以后可以直接导入用户库
3.在web.xml中配置FilterDispatcher
struts2框架是基于mvc模式的,他提供了核心控制类,对所有请求统一处理,这个控制器是一个名为FilterDispatcher 的Servlet过滤器充当的
2.1以前的版本配置模板如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
4.编写Action类,实现Action接口,返回5中静态数据类型结果
5.在struts.xml文件中配置action:一个action创建完成后,还要为其配置一个URL,这样,FilterDispatcher才知道URL对应哪个action,当截止到URL时,FilterDispatcher就调用对应的action对请求进行处理
模板如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="HelloWorld" extends="struts-default">
<action name="HelloWorld" class="org.sunxin.struts2.ch02.action.HelloWorldAction">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
6.发布测试
步骤:
1.创建web项目
2.导入struts2的jar包,我新建了一个用户库,以后可以直接导入用户库
3.在web.xml中配置FilterDispatcher
struts2框架是基于mvc模式的,他提供了核心控制类,对所有请求统一处理,这个控制器是一个名为FilterDispatcher 的Servlet过滤器充当的
2.1以前的版本配置模板如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
4.编写Action类,实现Action接口,返回5中静态数据类型结果
5.在struts.xml文件中配置action:一个action创建完成后,还要为其配置一个URL,这样,FilterDispatcher才知道URL对应哪个action,当截止到URL时,FilterDispatcher就调用对应的action对请求进行处理
模板如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="HelloWorld" extends="struts-default">
<action name="HelloWorld" class="org.sunxin.struts2.ch02.action.HelloWorldAction">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
6.发布测试
相关文章推荐
- 自己第一个汇编程序:Hello World !
- silverlight的第一个程序hello world.
- 第一个QT程序,Hello World
- Hello World 第一个程序
- Java 第一个Hello world 程序
- JAVA初学者第一个程序“Hello World”常见的错误及处理方法
- 第一个C#程序Hello World
- 2013 duilib入门简明教程 -- 第一个程序 Hello World(3)
- 在 mac os 上运行 kotlin native 的第一个程序:hello world
- 使用Eclipse编写第一个“Hello World!”程序
- 基于Xcode4开发第一个iPhone程序:“Hello World”
- Android 学习第一天 Android的第一个程序Hello World
- 【Android开发】Android开发环境搭建----第一个Android程序Hello World(中)
- 内核第一个程序之Hello World!
- 第一个go程序hello world讲解
- Springboot的第一个Hello World程序
- 0506第一个汇编程序Hello World
- C++之第一个程序Hello World,使用IO库输出Hello World
- 搭建第一个struts2框架web程序
- Praat 学习日志2--第一个脚本程序,输出“hello world!”