对不起,标题应该是转发而不是重发。即forward
解决方案 »
- 我想在让多个用户共享一个页面里面的内容(包括图片)该如何做?
- Missing message for key submit1
- struts2 . js给当前页面传值
- java 数据库查询 OutOfMemoryError
- Jakarta里面有一个可以把数组转换为ArrayList的是哪个类方法?
- 做过RssReader的请进,全额分数只送一人!!
- 各位大侠,请教一下,在jsp中怎样使用RMI,在线等
- 一个入门问题
- 请帮忙,关于java的mail的方法!!!
- 借给大家BEA的WEBLOGIC认证考试的标准培训资料!(仅限北京!!!!)
- 在持久化类的set方法里写逻辑的问题!送分!!
- 怎样在eclipse中建立一个dynamic web project 需要下载什么插件吗?
你这个报错应该是你的/login/loginLogin.do配置有问题
难道是这种loginLogin.do这种写法forward不支持?
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- Configuration for the member package. -->
<package name="Login" namespace="/login" extends="struts-default">
<action name="*Login" method="{1}" class="com.tongcard.merchant.web.actions.login.LoginAction">
<result name="input">/login/login.jsp</result>
<result name="success">/main.jsp</result>
<result name="logout">/login/login.jsp</result>
</action>
</package>
</struts>
建议你把这个完整的路径打出来看看。。
、loginLogin.do这种写法forward 是支持的
我以前经常这么写对了
你是不是req.getRequestDispatcher( "/login/loginLogin.do ").forward(req,res);
do后面多了个空格啊
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="demo-website" 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"> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:config/spring/spring-application.xml
</param-value>
</context-param> <context-param>
<param-name>webAppRootKey</param-name>
<param-value>operation_portal.root</param-value>
</context-param> <context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:config/log4j.properties</param-value>
</context-param> <context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param> <listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener> <listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener> <listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener> <context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/classes/config/tiles/tiles-defs.xml,
/WEB-INF/classes/config/tiles/tiles-member-defs.xml,
/WEB-INF/classes/config/tiles/tiles-merchant-defs.xml,
/WEB-INF/classes/config/tiles/tiles-point-defs.xml,
/WEB-INF/classes/config/tiles/tiles-sales-defs.xml,
/WEB-INF/classes/config/tiles/tiles-trade-defs.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener> <filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <filter>
<filter-name>CheckCookieFilter</filter-name>
<filter-class>
com.tongcard.merchant.web.filter.CheckCookieFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>CheckCookieFilter</filter-name>
<url-pattern>/index.jsp</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
<init-param>
<param-name>actionPackages</param-name>
<param-value>com.tongcard.merchant.web.actions</param-value>
</init-param>
</filter> <filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
</web-app>
当你的请求进来,到CheckCodeFilter的时候,你对cookie进行的判断,如果取不到Cookie的内容,就跳转到你说的login.do,这个是不会错的。
但在Filter中没有执行你的chain.doFilter()方法,这样的话接下来的请求将不会去走你的struts2这个Filter,那么你的Action也就映射不过去了,
所以会报404错误。这是我的理解,如果有达人发现有问题,请帮我指出来,共同学习。建议:
不要在Filter里面做这样的判断,在Action里面去判断,比如加个Index.do之类的,这样就不会有问题了,希望能帮到楼主
是不是定位jsp不需要走struts2的org.apache.struts2.dispatcher.FilterDispatcher,而类似于.do什么的就需要这个类去翻译。请grubbyfan兄指教。
2. 如果你用filter,那么当你进行转发的时候,Servlet容器会直接去找那个文件,比如你这里是/login/loginLogin.do,假设你的login目录下真的有
loginLogin.do这个文件,那么它也是可以找的到的(你不信可以试一下),所以不管是定位什么文件,只要它存在,就可以找到。
3. 建议:考虑通用性的话你可以通过自定义一个拦截器实现(Interceptor),Struts2里面自定义Interceptor很简单的,你可以参考这篇文章
http://www.blogjava.net/max/archive/2006/12/06/85925.html