struts2注解配置注意事项
2013-04-11 23:28
525 查看
今天在写struts2的注解时遇到了低级错误下面给个分享:
总结action配置:
这段配置相信大家都很熟悉,但是重点来了:
struts2默认会去找*.actions或*.action包下的action,这点很关键。
所以我总结了配置注解有两种方式:
A.将你的action文件放在*.actions或*.action包下就可以了,注解生效(注意一定是在*.actions或*.action包下哦)
B.你的action文件可以随便放,那么就需要在web.xml中配置参数:
以上是这次错误的总结,希望能给各位朋友带来帮助!
总结action配置:
package com.test.web.actons; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Namespace; import org.apache.struts2.convention.annotation.Result; import com.opensymphony.xwork2.ActionSupport; @Namespace(value="/test") public class TestAction extends ActionSupport{ private static final long serialVersionUID = 2118537853660540192L; @Action(value="login",results={@Result(location="bookList.jsp")}) public String login() throws Exception{ System.out.println("hello struts2!!"); return SUCCESS; } }
这段配置相信大家都很熟悉,但是重点来了:
struts2默认会去找*.actions或*.action包下的action,这点很关键。
所以我总结了配置注解有两种方式:
A.将你的action文件放在*.actions或*.action包下就可以了,注解生效(注意一定是在*.actions或*.action包下哦)
B.你的action文件可以随便放,那么就需要在web.xml中配置参数:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 添加struts2、sitemesh支持 --> <filter> <filter-name>struts</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>actionPackages</param-name> <param-value>com.test.action</param-value> </init-param> </filter> <filter-mapping> <filter-name>struts</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
以上是这次错误的总结,希望能给各位朋友带来帮助!
相关文章推荐
- struts2注解配置注意事项
- struts2注解配置注意事项
- struts2注解配置注意事项
- java 使用quartz 定时xml 配置 与注解 以及注意事项
- springmvc mybatis 基于全注解事务配置注意事项
- Struts2 零配置注意事项
- Struts2 零配置注意事项
- Struts2 零配置注意事项
- 使用注解配置hibernate实体类的注意事项——原载于我的百度空间
- struts2 注解方式注册action中 namespace 的注意事项
- struts2使用注解时返回json时应注意的事项
- spring框架DAO搭配注解配置时注意事项
- Struts2的配置文件加载顺序及常用常量名及更改方法、注意事项
- springmvc 基于全注解事务配置注意事项
- springmvc mybatis 基于全注解事务配置注意事项
- 《struts2 in action》学习问题——零配置——几点注意事项
- springmvc mybatis 基于全注解事务配置注意事项
- 关于Struts2注解配置的若干注意点
- ssh免密码登陆配置及注意事项
- svn仓库迁移及配置注意事项?