正在用 SSH(struts2.0+spring3.0+hibernate2.0)开发一个项目,但是struts2.0 请求action 后转到的页面的后缀都成了XXX_XXXX.action (我用的通配符设置的action).看着很是不习惯,需要修改!!!
(前台的页面显示需要数据库中的数据,所以显示之前必须访问数据库!!)
解决方案:
1,开始想用Ajax技术。来取得数据库的数据。但一旦数据量过大或过于凌乱,则是个大问题!
2,由于struts2.0 访问数据库之后,页面显示的url 都是访问的action 的名字。现在考虑修改struts2.0的拦截器的拦截后缀。(默认为.action,现想修改为.jsp)如此以来,则前台的URL 就不会出现XXX_XXXX.action ,而是XXX.jsp.
查阅资料:得到: 可以在 struts.xml 配置文件中 修改 拦截器的拦截属性:
修改struts.xml文件,在<struts></struts>中加入下面这句话。
<constant name="struts.action.extension" value="action,jsp" />
如此以来,strtus2.0 就开始 拦截 后缀为 .action 和 .jsp 的请求。
例:如果访问的页面为 index.jsp
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.0.dtd">
<struts>
<!-- 程序国际化 指定国际化资源文件 -->
<constant name="struts.custom.i18n.resources"
value="ApplicationResources" />
<constant name="struts.i18n.encoding" value="gb2312" />
<constant name="struts.i18n.reload" value="false"></constant>
<constant name="struts.action.extension" value="action,jsp" />
<!-- 设置上传文件时不要Tomcat的临时路径,使用设置的值 -->
<constant name="struts.multipart.saveDir" value="/temp" />
<!-- 设置上传文件大小 -->
<constant name="struts.multipart.maxSize" value="524280" />
<package name="outlook" extends="struts-default">
<global-results>
<!-- 下面定义的结果对所有的Action都有效 -->
<result name="exception">/error.jsp</result>
</global-results>
<global-exception-mappings>
<!-- 指Action抛出Exception异常时,转入名为exception的结果。 -->
<exception-mapping exception="java.lang.Exception"
result="exception" />
</global-exception-mappings>
</package>
<!-- 网站后台配置 -->
<package name="Outlook" extends="struts-default" namespace="/">
<interceptors>
<!-- 定义了一个名为authority的拦截器 -->
<interceptor name="authority"
class="org.boss.action.AuthorityInterceptor">
</interceptor>
</interceptors>
<!-- 定义全局Results -->
<global-results>
<result name="success">/barhome/success.jsp</result>
<result name="none">/barhome/doerror.jsp</result>
<result name="exception">/barhome/error.jsp</result>
</global-results>
<global-exception-mappings>
<!-- 指Action抛出Exception异常时,转入名为exception的结果。 -->
<exception-mapping exception="java.lang.Exception"
result="exception" />
</global-exception-mappings>
<action name="index" class="org.boss.action.OutLookAction">
<result name="goindex">/home.jsp</result>
</action>
</package>
</struts>
action 的代码
public String execute()throws Exception{
this.getChannel();// 网站频道信息
return "goindex";
}
OK ,问题解决!!现在URL的显示正常了。!!
分享到:
相关推荐
java struts如何隐藏提交后缀.action, .do
Struts2升级到2.5.30,问题解决及过程记录, 文章详见:https://blog.csdn.net/sinat_36743893/article/details/124582101
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,...
org.springframework.web.struts-3.1.0.M2.jar
struts2实现改写在url后缀的方法,如XX.do--->改写为xx.html等,方便试用,一目了然
struts-taglib-1.3.8.jar struts-taglib-1.3.8.jar
用URL扩展名来确定是否这个请求是被用作Struts action,其实也就是设置 action的后缀,例如login.do的'do'字。 struts.configuration The org.apache.struts2.config.Configuration implementation class org....
Manning.Struts.2.in.Action.May.2008
struts2--2.Action
Struts2--3.Action及相关-1
struts-2.3.34-all.rar,包括app,docs,lib,src
Java.Web整合开发王者归来.JSP+Servlet+Struts+Hibernate+Spring.part2.rar
Struts2--3.Action及相关-2
Java.Web开发JSP.Servlet.Struts.Spring.Hibernate.Ajax.rar
struts2的token实现.
绝对可以解决这个这个问题。Struts初学者绝对可以受用的方法。
struts1.38包,struts-core-1.3.8.jarstruts1.38包,struts-core-1.3.8.jar
零基础学Java.Web开发:JSP.Servlet.Struts.Spring.Hibernate.Ajax(PPT).
Struts2漏洞检查工具Struts2.2019.V2.3
Struts2文件批量上传.zip Struts2文件批量上传.zip Struts2文件批量上传.zip Struts2文件批量上传.zip Struts2文件批量上传.zip