- 浏览: 511640 次
- 性别:
- 来自: 宁波
文章分类
- 全部博客 (137)
- JQuery component (3)
- Web编程控件 (7)
- java (19)
- database (9)
- Web Service (6)
- XML (2)
- FTP (2)
- SSH2 (18)
- javascript (3)
- arcgis (7)
- geoserver (1)
- Openscales (2)
- FME (6)
- HttpClient (3)
- portal (6)
- oracle goldengate (7)
- oracle (3)
- 命令锦集 (1)
- web容器 (3)
- NB博客链接 (2)
- 设计模式 (0)
- ext (2)
- 小工具 (12)
- Flex (1)
- LINUX (1)
- Android (1)
- Maven 入门 (2)
- 负载均衡 (1)
- openlayers (2)
- Flexkkjk (0)
最新评论
-
lgh1992314:
ApplicationContext context = We ...
Spring中的ContextLoaderListener使用 -
lgh1992314:
ContextLoaderServletSpring3.0后删 ...
Spring中的ContextLoaderListener使用 -
gaoqiangjava:
...
Spring中的ContextLoaderListener使用 -
liude33:
好资料啊,网上这方面的资料好少。
goldengate 学习资料 -
AKka:
在实体类中加上@Transient 注解后,为什么还会在数据库 ...
JPA注解 转
还是已登录来说明下这个Action的配置,这里要说的Action的配置不是在src/struts.xml中,而是用注解方式来进行配置的
前提是除了基本的那六个jar包之外,还需要一个struts-2.1.8.1\lib\struts2-convention-plugin-2.1.8.1.jar
不过struts.xml还是要有的
具体示例
Login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>login</title>
</head>
<body>
<form action="test/hello-world.action">
姓名:<input type="text" name="username"/><br>
密码:<input type="password" name="password"/><br>
<input type="submit" value="登陆 ">
</form>
</body>
</html>
src/struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- struts2的国际化大致上分为页面的国际化,Action的国际化以及xml的国际化-->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- 是否使用struts的开发模式。开发模式会有更多的调试信息。默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.devMode" value="true" />
<!-- 指定被struts2处理的请求后缀类型。多个用逗号隔开 -->
<constant name="struts.action.extension" value="action,do"/>
<!-- 当struts.xml改动后,是否重新加载。默认值为false(生产环境下使用),开发阶段最好打开 -->
<constant name="struts.configuration.xml.reload" value="true"/>
<!-- 设置浏览器是否缓存静态内容。默认值为true(生产环境下使用),开发阶段最好关闭 -->
<constant name="struts.serve.static.browserCache" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
<!--
指定由spring负责action对象的创建
<constant name="struts.objectFactory" value="spring" />
<include file="struts-plt.xml" />
<include file="struts-org_user.xml" /> -->
</struts>
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">
<!-- struts2.3.1 begin-->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.sspm.action</param-value>
</init-param>
<init-param>
<param-name>config</param-name><!-- 服务器运行的时候加载struts 配置文件,没有注解似乎报错 -->
<param-value>struts-default.xml,struts-plugin.xml,WEB-INF/class/struts.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- struts2.3.1 end-->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
HelloWorldAction.java
package com.sspm.action.test;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.opensymphony.xwork2.ActionSupport;
/**
* Struts2基于注解的Action配置
* @author wangpj
*
*/
@ParentPackage("struts-default")
@Namespace("/test")
//@Namespace("")
@Results(
{
@Result(name="success",location="/jsp/ok.jsp"),
@Result(name="error",location="/jsp/errors.jsp")
}
)
@ExceptionMappings(
{
@ExceptionMapping(exception="java.lange.Exception",result="error")
}
)
@InterceptorRefs({
@InterceptorRef("defaultStack")
})
public class HelloWorldAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private String username;
private String password;
//或者写成 @Action(value = "login")
//请求url: http://localhost:8080/sshtest/test/login!login.action
//请求其他方法: http://localhost:8080/sshtest/test/login!add.action
// 跳转页 走的是全部Result
@Action("login")
public String login() throws Exception{
System.out.println("===========");
return SUCCESS;
}
//有“/” 命名空间被替换
//请求url: http://localhost:8080/sshtest/other/add!add.action
//请求其他方法 http://localhost:8080/sshtest/other/add!login.action
// 跳转页 走的是局部Result
@Action(value="/other/add",results = { @Result(name = "success", location = "/index.jsp")})
public String add() throws Exception{
System.out.println("add>>>>>>");
return SUCCESS;
}
//默认请求action类,去掉结尾"Action",然后按照驼峰规则添加“-”,字符全部小写
//请求url: http://localhost:8080/sshtest/test/hello-world.action?username=abc&password=123
@Override
public String execute() throws Exception {
//条件password.equals("123") 时 password为null时抛出异常 转向error
if ("abc".equals(username)&&"123".equals(password)) {
System.out.println("abc>>>>>>");
return SUCCESS;
} else {
System.out.println("other>>>>>>");
return ERROR;
}
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
ok.jsp和errors.jsp我就不贴出来了
注解配置的解释
1) @ParentPackage 指定父包
2) @Namespace 指定命名空间
3) @Results 一组结果的数组
4) @Result(name="success",location="/msg.jsp") 一个结果的映射
5) @Action(value="login") 指定某个请求处理方法的请求URL。注意,它不能添加在Action类上,要添加到方法上。
6) @ExceptionMappings 一级声明异常的数组
7) @ExceptionMapping 映射一个声明异常
8) @InterceptorRefs 拦截器
发表评论
-
spring 线程池
2013-10-24 07:30 0spring 配置文件 <!-- app ... -
在javaee项目里集成了hibernate,在使用注解映射表时,老是出现的错误
2012-02-06 14:11 2766在javaee项目里集成了hibernate,在使用注解映射表 ... -
nested exception is org.hibernate.AnnotationException: mappedBy reference an unk
2012-02-06 14:10 4932现有部门与用户两个表 一对多关系 在进行hibern ... -
Hibernate Annotation (Hibernate JPA注解) 实例
2012-01-17 10:06 4031hibernate: 3.6 数据库 oracle ... -
JPA注解 转
2012-01-17 09:53 61731、@Entity(name="EntityName ... -
hibernate反向映射 no entries available
2012-01-16 15:07 3992做项目时,有时需要用hibernate反向映射表,很多时候会出 ... -
hibernate 3配置
2012-01-16 13:29 989hibernate 搭建 1、所需jar包antlr-2.7 ... -
Struts2+JSON+jQuery实现异步交互数据时选择要序列化的属性(二使用XML配置方式)
2012-01-13 09:46 1250只需在XML配置就可以了,配置方式是: Xml代码 ... -
Struts2+JSON+jQuery实现异步交互数据时选择要序列化的属性(一注解方式转)
2012-01-13 09:45 1608在使用Struts2的JSON插件,实现Action中的属性序 ... -
Struts2练习-最基本的示例 —转
2012-01-11 16:52 1287转-(查看更多内容请点击http://javacrazyer. ... -
struts2.3.1 注解 HTTP Status 404 - There is no Action mapped for namespace
2012-01-11 16:49 3612使用struts2.3.1 注解配置时 自己将配置文件stru ... -
Spring JDBC模板类—org.springframework.jdbc.core.JdbcTemplate
2011-12-01 14:44 1927转:http://just-do-myself.iteye.c ... -
DWR + Spring 配置问题 No class by name
2011-11-23 16:28 4023[framework] 2011-07-26 16:51:0 ... -
DWR Spring 注解 整合
2011-09-22 23:18 14131、添加相应jar包 2、配置web.xml <?x ... -
项目无法使用Hibernate Reverse Engineering ,解决办法
2011-04-13 18:22 1782手工自己编写hibernater的配置文件。可惜当采用Hibe ... -
用AnnotationSessionFactoryBean生成sessionFactory时报错不能创建sessionFactoyBean(转)
2011-02-16 11:04 4065报错信息: [junit] Testcase: testCr ... -
Spring中的ContextLoaderListener使用
2011-01-18 10:30 40189最近 项目中使用Spring 时,applicationCon ... -
Struts2.1.6+Spring2.5.6+Hibernate3.3.1全注解实例详解(一)(转载)
2010-12-16 13:40 1154在JavaEE企业级开发中,以SSH2框架为核心的应用 ...
相关推荐
struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...
-- 为修复struts2 s2-016、s2-017漏洞,重写DefaultActionMapper --> <bean type="org.apache.struts2.dispatcher.mapper.ActionMapper" name="myDefaultActionMapper" class=...
struts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jarstruts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jar
struts-core-1.3.10.jar, struts2-cdi-plugin-2.3.30.jar, struts2-codebehind-plugin-2.3.30.jar, struts2-config-browser-plugin-2.3.30.jar, struts2-convention-plugin-2.3.30.jar, struts2-core-2.3.30.jar, ...
2017年7月7日,Apache Struts发布最新的安全公告,Apache Struts2-strus1-plugin插件存在远程代码执行的高危漏洞,漏洞编号为CVE-2017-9791(S2-048),主要受影响的Struts版本为:2.3.x。 攻击者可以构造恶意的字段值...
struts-taglib-1.3.8.jar struts-taglib-1.3.8.jar
在通过注解方式配置的ssh框架基础上通过修改得到的基于注解方式ssm开发框架
Struts 2使用注解配置Action,不配置struts.xml,通过注解直接配置action
struts2-config-browser-plugin-2.3.24.jar, struts2-core-2.3.24.jar, struts2-jasperreports-plugin-2.3.24.jar, struts2-jfreechart-plugin-2.3.24.jar, struts2-pell-multipart-plugin-2.3.24.jar, struts2-...
struts2 s2-045
struts2-json-plugin,Struts JSON插件
赠送jar包:struts2-json-plugin-2.3.24.jar; 赠送原API文档:struts2-json-plugin-2.3.24-javadoc.jar; 赠送源代码:struts2-json-plugin-2.3.24-sources.jar; 赠送Maven依赖信息文件:struts2-json-plugin-...
struts2-ssl-plugin-1.2.1.jar
struts2-bean-validation-plugin-2.5.2.jar, struts2-cdi-plugin-2.5.2.jar, struts2-config-browser-plugin-2.5.2.jar, struts2-convention-plugin-2.5.2.jar, struts2-core-2.5.2.jar, struts2-dwr-plugin-2.5.2....
包含Struts2框架的核心类库,以及Struts2的第三方插件类库 struts2-core-2.0.14 xwork-2.0.7 ognl-2.6.11 commons-logging-1.0.4 freemarker-2.3.8 等等。
struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-...
struts2-convention-plugin-2.3.32
【Struts2】〖所有依赖jar包〗struts-2.3.37-lib 我寻见一片海 碧蓝且耀着光 大片船只航行其上 都向着远方 Shared by Foriver_江河 © 1997-8023 江河 All Rights Reserved.
struts2-dojo-plugin-2.3.4 jar 日期控件的jar包 需要的自行下载
包含struts2-core-2.5.10.1.jar,struts2-jfreechart-plugin-2.5.10.1.jar,struts2-json-plugin-2.5.10.1.jar,struts2-junit-plugin-2.5.10.1.jar,struts2-bean-validation-plugin-2.5.10.1.jar,struts2-cdi-...