struts配置文件
<?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>
<!-- default 在默认的命名空间 -->
<package name="default" extends="struts-default">
<!-- 全局结果定义 -->
<global-results>
<result name="login" type="redirect">/login.action</result>
<result name="sqlException" type="chain">/sqlException.action</result>
<result name="exception">/exception.jsp</result>
</global-results>
<global-exception-mappings>
<!-- 全局异常映射定义 -->
<exception-mapping exception="java.sql.SQLException" result="sqlException"/>
<exception-mapping result="exception" exception="java.lang.Exception"></exception-mapping>
</global-exception-mappings>
<action name="login" class="...">
<!-- 局部异常定义 -->
<exception-mapping exception="rog.coolove.MyException" result="login"/>
<result type="redirectAction">${nextAction}</result>
</action>
</package>
</struts>
import org.apache.struts2.config.Namespace;
import org.apache.struts2.config.Result;
import org.apache.struts2.config.Results;
import org.apache.struts2.dispatcher.ServletDispatcherResult;
import com.opensymphony.xwork2.Action;
@ParentPackage("default")
@Namespace("/test")
@Result("/success.jsp")
@Results({
@Result(name="input", value="/input.jsp"),
@Result(name="error", value="/error.jsp", type=ServletDispatcherResult.class)
})
public class AnnotationAction implements Action
{
@Override
public String execute() throws Exception
{
return SUCCESS;
}
public String input() throws Exception
{
return INPUT;
}
public String error() throws Exception
{
return ERROR;
}
}
web.xml文件
<?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>
<init-param>
<!-- 需要配置filter-->
<param-name>actionPackages</param-name>
<param-value>cn.com.sise.expert.web</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
分享到:
相关推荐
Struts 2使用注解配置Action,不配置struts.xml,通过注解直接配置action
Struts2+spring注解配置 很好哦
Struts2 注解配置 Action 及拦截器是 Struts2 框架中的核心组件之一,负责处理用户请求并返回响应结果。下面,我们将通过详细的解释和示例代码,来介绍 Struts2 中的注解配置 Action 及拦截器几种不同方式的写法对应...
使用struts2基于注解(零配置)实现的文件上传与下载的代码,可以正常运行
Struts2注解详细说明文档,详细讲述struts2的注解使用
Struts2 中 Action 接收参数的方法 Struts2 框架中,Action 组件可以通过多种方式接收参数,这些方式包括使用 Action 的属性、使用 DomainModel 和使用 ModelDriven。下面将详细介绍这些方法: 使用 Action 的属性...
struts2详解! 从struts2.1开始,struts2不再推荐使用Codebehind作为零配置插件,而是改为使用Convention插件来支持零配置,和Codebehind相比,Convention插件更彻底,该插件完全抛弃配置信息,不仅不需要是使用...
Maven实现struts2注解
Mybatis整合Spring3和Struts2项目注解开发集合包
注解实现的页面跳转其特点是不用配置文件struts.xml因而可以实现零配置,同时由于有注解的功能,所以说大大增加了程序的可维护性。
Struts 2实战 struts2 in Action
使用MyEclipse和Gradle ...(2)struts2-anotation-lib.zip 注解式开发需要用的lib包 (3)struts2-anotation_eclipse.zip 注解时开发myeclipse项目压缩 (4)struts2-anotation_Gradle.zip 注解式开发的Gradle文件压缩
Struts2Demo 注解的小例子,jar包全包括
Struts2注解开发jar,必须导入struts2-convention-plugin-2.3.15.jar包,它在struts2安装包下lib目录中。
struts2 spring mybatise 注解整合
struts2将请求在Action中封装为Map并将配置文件放到web-info中还可以自定义配置文件位置就是不将struts.xml放到src下但还是不如spring mvc 的封装来得方便
该例子为struts2注解与拦截器demo,利用myEclipse8.5开发,导入刚才后,自动加载所需struts2的jar包,可以直接运行,是初学struts2注解、拦截器很好的例子,保证10分钟学会2种技术,愿意分享给大家。
maven整合struts2全注解,
Struts2的框架及注释和使用法,希望大家支持,我们一起努力,谢谢!
测试struts2中的action