构建一个Struts2项目
2016-02-04 00:07
441 查看
Struts2
1、建项目
—–用MyEclipse建一个web项目
2、导包
3、修改web.xml文件
因为web项目一启动就会访问web.xml文件,得到初始化配置信息,所以你要在web.xml文件中配置Struts关于filter的信息
4、写相关action类
5、写Struts.xml配置文件
6、发布访问
localhost:8080/Struts2_20160213/HelloWorld.action
Struts 2以WebWork为核心,采用拦截器的机制来处理用户的请求,这样的设计也使得业务逻辑控制器能够与ServletAPI完全脱离开
1、建项目
—–用MyEclipse建一个web项目
2、导包
3、修改web.xml文件
因为web项目一启动就会访问web.xml文件,得到初始化配置信息,所以你要在web.xml文件中配置Struts关于filter的信息
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_9" 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"> <display-name>Struts Blank</display-name> <filter> <!-- 配置Struts2核心Filter的名字 --> <filter-name>struts2</filter-name> <!-- 配置Struts2核心Filter的实现类 --> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <!-- 配置Filter拦截的URL --> <filter-mapping> <!-- 配置Struts2的核心FilterDispatcher拦截所有用户请求 --> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
4、写相关action类
package com.xingyao.www.action; import com.opensymphony.xwork2.ActionSupport; //一个类实现ActionSupport就成为一个action类(还要在struts.xml里面配置信息) public class HelloWorldAction extends ActionSupport { private static final long serialVersionUID = 1L; @Override //重写一个基本方法 public String execute() throws Exception { System.out.println("执行action"); return "SUCCESS"; } }
5、写Struts.xml配置文件
<?xml version="1.0" encoding="UTF-8"?> <!-- 规定Struts.xml的格式 --> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- 规定包,这是全部设为默认 --> <package name="default" namespace="/" extends="struts-default"> <!-- 配置helloWorldAction的信息名为:HelloWorld(用于页面访问的时候用),配置它的类路径 --> <action name="HelloWorld" class="com.xingyao.www.action.HelloWorldAction"> <!-- 配置返回结果名为SUCCESS,则服务器跳转到index.jsp --> <result name="SUCCESS">index.jsp</result> </action> </package> </struts>
6、发布访问
localhost:8080/Struts2_20160213/HelloWorld.action
相关文章推荐
- Struts - 标签库
- struts1.0于struts2.0的比较
- Struts2中关于namespace的学习心得
- Struts2----自定义action的学习心得
- HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login!welcome] associ
- struts2
- struts 学习笔记
- struts2框架架构流程
- struts2.0拦截器(实现未登录的用户不能访问系统的页面)(转)
- Struts2+jQuery+JSON实现异步交互
- 软件开发疑惑解答
- ajax ssh 整合
- struts2 @Action给方法注解
- struts2登陆拦截器
- struts2框架原理
- web.xml
- web.xml
- struts2框架原理
- struts2登陆拦截器
- struts2 @Action给方法注解