求struts2+spring+urlrewrite整合的项目例子
各位大神我想把
请求的后缀.action去掉,访问静态页面的<rule></rule>我会配置,但是整合spring的action请求不会,想各位大神求助
web.xml <!-- URL ReWriter --> <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <!-- set the amount of seconds the conf file will be checked for reload can be a valid integer (0 denotes check every time, empty/not set denotes no reload check) --> <init-param> <param-name>confReloadCheckInterval</param-name> <param-value>0</param-value> </init-param> <!-- you can disable status page if desired can be: true, false (default true) --> <init-param> <param-name>confPath</param-name> <param-value>/WEB-INF/conf/url/urlrewrite.xml</param-value> </init-param> <init-param> <param-name>statusEnabled</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>logLevel</param-name> <param-value>WARN</param-value> </init-param> <init-param> <param-name>statusEnabledOnHosts</param-name> <param-value>localhost</param-value> </init-param> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> <init-param> <param-name>config</param-name> <param-value> struts-default.xml, struts-plugin.xml, ../conf/struts/struts.xml </param-value> </init-param> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <filter> <filter-name>struts-cleanup</filter-name> <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/conf/spring/*.xml </param-value> </context-param>
struts.xml
<?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.3.dtd"> <struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" /> <constant name="struts.devMode" value="false" /> <!-- <constant name="struts.action.extension" value="do,action"></constant> --> <constant name="struts.ognl.allowStaticMethodAccess" value="true" /> <constant name="struts.configuration.xml.reload" value="true" /> <!-- 全局语言资源文件 --> <constant name="struts.custom.i18n.resources" value="language" /> <constant name="struts.i18n.reload" value="true"></constant> <!-- 设置默认的locale和字符编码 --> <constant name="struts.i18n.encoding" value="UTF-8" /> <!-- 下面配置视图主题为 Simple 防止它自动生成一些标签 --> <constant name="struts.ui.theme" value="simple" /> <!-- 下面的 struts.objectFactory 是将Action交给Spring管理 --> <constant name="struts.objectFactory" value="spring" /> <constant name="struts.multipart.saveDir" value="d:\temp" /> <package name="ssltools" namespace="/tools" extends="struts-default"> <default-action-ref name="show" /> <global-results> <result name="message">/WEB-INF/page/message.jsp</result> <result name="error">/WEB-INF/page/error.jsp</result> <result name="login" type="redirect">/login.jsp</result> </global-results> <action name="show" class="ssltoolsPageAction" method="show"> <result name="success">/WEB-INF/pages/tools.jsp</result> </action> <!-- 证书格式转换 表单处理 --> <action name="formatAction" class="formatAction" method="format"> <interceptor-ref name="fileUpload"> <param name="maximumSize">32768</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> <result name="success" type="stream"> <!-- 指定下载文件的内容类型,text/plain是默认类型 --> <param name="contentType">text/plain</param> <!-- inputName默认值是inputStream,如果action中用于读取下载文件内容的属性名是inputStream,那么可以省略这个参数 --> <param name="inputName">filestream</param> <!--动态获取文件名,从Action中的取得filename --> <param name="contentDisposition"> attachment;filename="${filename}" </param> <param name="bufferSize">2048</param> </result> <result name="format">/WEB-INF/pages/tools.jsp</result> </action> <!-- CSR生成 --> <action name="csrGeneratorAction" class="csrGeneratorAction"> <result name="success">/WEB-INF/pages/tools.jsp</result> </action> <!-- CSR查看 --> <action name="csrDecoderAction" class="csrDecoderAction"> <result name="success">/WEB-INF/pages/tools.jsp</result> </action> <!-- 证书查看 --> <action name="certDecoderAction" class="certDecoderAction"> <result name="success">/WEB-INF/pages/tools.jsp</result> </action> <!-- SSL检测 --> <action name="sslCheckAction" class="sslCheckAction"> <result name="success">/WEB-INF/pages/tools.jsp</result> </action> <!-- 私钥加解密 --> <action name="keyEncAndDecAction" class="keyEncAndDecAction"> <result name="success">/WEB-INF/pages/tools.jsp</result> </action> <!-- 公私钥匹配 --> <action name="keyMatchAction" class="keyMatchAction"> <result name="success">/WEB-INF/pages/tools.jsp</result> </action> </package> </struts>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <bean name="ssltoolsPageAction" class="com.trustasia.ssltools.action.SSLtoolsPageAction" scope="request" /> <bean name="formatAction" class="com.trustasia.ssltools.action.FormatAction" scope="request" p:certFormatService-ref="certFormatService" /> <bean name="csrGeneratorAction" class="com.trustasia.ssltools.action.CsrGeneratorAction" scope="request" p:csrGeneratorService-ref="csrGeneratorService" /> <bean name="csrDecoderAction" class="com.trustasia.ssltools.action.CsrDecoderAction" scope="request" p:csrDecoderService-ref="csrDecoderService" /> <bean name="certDecoderAction" class="com.trustasia.ssltools.action.CertDecoderAction" scope="request" p:certDecoderService-ref="certDecoderService" /> <bean name="sslCheckAction" class="com.trustasia.ssltools.action.SSLCheckAction" scope="request" p:sslCheckService-ref="sslCheckService" /> <bean name="keyEncAndDecAction" class="com.trustasia.ssltools.action.KeyEncAndDecAction" scope="request" p:keyEncAndDecService-ref="keyEncAndDecService" /> <bean name="keyMatchAction" class="com.trustasia.ssltools.action.KeyMatchAction" scope="request" p:keyMatchService-ref="keyMatchService" /> <bean name="certFormatService" class="com.trustasia.ssltools.service.impl.CertFormatServiceImpl" p:certFormatBean-ref="certFormatBean" /> <bean name="csrGeneratorService" class="com.trustasia.ssltools.service.impl.CsrGeneratorServiceImpl" p:csrGeneratorBean-ref="csrGeneratorBean" /> <bean name="csrDecoderService" class="com.trustasia.ssltools.service.impl.CsrDecoderServiceImpl" p:csrDecoderBean-ref="csrDecoderBean" /> <bean name="certDecoderService" class="com.trustasia.ssltools.service.impl.CertDecoderServiceImpl" p:certDecoderBean-ref="certDecoderBean" /> <bean name="sslCheckService" class="com.trustasia.ssltools.service.impl.SSLCheckServiceImpl" p:sslCheckBean-ref="sslCheckBean" /> <bean name="keyEncAndDecService" class="com.trustasia.ssltools.service.impl.KeyEncAndDecServiceImpl" p:keyEncAndDecBean-ref="keyEncAndDecBean" /> <bean name="keyMatchService" class="com.trustasia.ssltools.service.impl.KeyMatchServiceImpl" p:keyMatch-ref="keyMatch" /> <bean name="certFormatBean" class="com.trustasia.ssltools.bean.CertFormatBean" /> <bean name="csrGeneratorBean" class="com.trustasia.ssltools.bean.CsrGeneratorBean" /> <bean name="csrDecoderBean" class="com.trustasia.ssltools.bean.CsrDecoderBean" /> <bean name="certDecoderBean" class="com.trustasia.ssltools.bean.CertDecoderBean" /> <bean name="sslCheckBean" class="com.trustasia.ssltools.bean.SSLCheckBean" /> <bean name="keyEncAndDecBean" class="com.trustasia.ssltools.bean.KeyEncAndDecBean" /> <bean name="keyMatch" class="com.trustasia.ssltools.util.KeyMatch" /> </beans>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
那表单里的数据怎么通过action传递呢,毕竟参数的传递个数是不确定的
回复
这就要看你怎么rewirte自定义正则表达式了
回复
能弱弱的求个项目例子么
回复
没有,我没有例子
这个我配过的,不行,我还用了spring了,比如:<s:form namespace="/tools" action="csrGeneratorAction"/>当我提交的时候会通过spring的配置文件去对应的bean,这个时候url就会是csrGeneratorAction.action,我只是想把url变好看点
我配过,但是不行,因为我是提交表单时的action,要去找spring配置文件里注入的bean,在这个地方凌乱了,不知道我说的清不清楚
只要你在urlrewrite中讲伪地址配置好。再在web中配置下Url就行吧。
唉,关键是现在项目要用struts2啊,没办法
建议上spring mvc 你会发现这个问题简直就不是个问题
谢谢了,但是不怎么看的明白,能给个具体点的例子么
回复
你把你的web.xml, struts.xml 这2个文件贴上来
回复
已经贴出来了