struts2配置codebehind

导入jar包struts2-codebehind-plugin-2.3.28.1.jar。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>StrutsDemo</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
  <filter>
    <description>struts2过滤器 </description>
    <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.nayi<!-- 包名,若配置多个,用逗号(,)分隔 -->
	  </param-value>
    </init-param>
    <init-param>
		<param-name>packages</param-name>
		<param-value>app/pages</param-value><!-- jsp页面 -->
	</init-param>
  </filter>
  
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>

</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">

<struts>

	<!-- struts2中action后缀名 -->
	<constant name="struts.action.extension" value="action" />

	<!-- 默认编码方式 -->
	<constant name="struts.i18n.encoding" value="utf-8" />

	<!-- 是否为开发模式,在开发模型中可以获得更多的跟踪信息 -->
	<constant name="struts.devMode" value="false" />

	<!-- 标签主题 -->
	<constant name="struts.ui.theme" value="pure" />

	<!-- 资源文件名称 -->
	<constant name="struts.custom.i18n.resources" value="globalMessages" />

	<!--静态资源文件配置 -->
	<constant name="struts.serve.static" value="true" />
	<constant name="struts.serve.static.browserCache" value="true" />
	
	<!-- 
	<constant name="struts.staticContentLoader"
		value="com.bonc.commons.struts2.dispatcher.StaticContentLoader"/>
 -->
	<!-- 在开发模式下启用 配置改变时自动加载 -->
	<constant name="struts.convention.classes.reload" value="true" />

	<!-- 允许Ognl表达式访问静态方法 -->
	<constant name="struts.ognl.allowStaticMethodAccess" value="true" />

	<!-- 上传文件的最大文件大小 -->
	<constant name="struts.multipart.maxSize" value="10485760" />

	<!-- action默认的父package,action将自动继承父package的所有属性,在action没有显式声明action的父package时生效 
	<constant name="struts.configuration.classpath.defaultParentPackage"
		value="pure-default" />
-->
	

	<!-- 在寻找资源时是否忽略大小写 -->
	<constant name="struts.configuration.classpath.forceLowerCase"
		value="false" />

	<!-- codebehind中查找action的返回结果资源时的默认文件夹 -->
	<constant name="struts.codebehind.pathPrefix" value="/app/pages/" />
	<constant name="struts.allowed.action.names" value="[a-zA-Z0-9._!/\-]*" />
	
	<constant name="struts.enable.DynamicMethodInvocation" value="true"/>

</struts>

使用方法:
对于上述的配置,若action的路径为com.nayi.test.Test ,则url应该为http://IP:端口号/项目名/test/Test.action,对应的jsp路径应为app/pages/test/Test.jsp。

对于请求方法的情况,若要请求Test的aaa(),url应为http://IP:端口号/项目名/test/Test!aaa.action。若aaa()的返回值为return “bbb”;,对应的jsp应为Test-bbb.jsp。

通过上述方法,可实现跳转的零配置。

具体使用的jar包如下:struts2-codebehind-plugin-2.3.28.1.jar,struts2-core-2.3.32.jar,xwork-core-2.3.32.jar。

有可能我的项目中的其他jar包也对此功能有影响,发一个全的(有一多半jar包只是为了使用org.springframework.orm.ibatis.SqlMapClientTemplate这个类)

asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
commons-fileupload-1.3.2.jar
commons-io-2.2.jar
commons-lang3-3.2.jar
commons-logging-1.1.3.jar
dom4j-1.6.1.jar
freemarker-2.3.22.jar
ibatis-2.3.4.726.jar
javassist-3.11.0.GA.jar
log4j-1.2.17.jar
ognl-3.0.19.jar
ojdbc14.jar
spring-aop-3.2.3.RELEASE.jar
spring-aspects-3.2.3.RELEASE.jar
spring-beans-3.2.3.RELEASE.jar
spring-context-3.2.3.RELEASE.jar
spring-context-support-3.2.3.RELEASE.jar
spring-core-3.2.3.RELEASE.jar
spring-expression-3.2.3.RELEASE.jar
spring-jdbc-3.2.3.RELEASE.jar
spring-orm-3.2.3.RELEASE.jar
spring-oxm-3.2.3.RELEASE.jar
spring-tx-3.2.3.RELEASE.jar
spring-web-3.2.3.RELEASE.jar
struts2-codebehind-plugin-2.3.28.1.jar
struts2-core-2.3.32.jar
xwork-core-2.3.32.jar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值