2013-07-20 52 views
0

我有一个登录页面和一个登录操作。当用户登录操作返回“成功”结果。并且它必须转到另一个行动。但我得到以下错误:struts2结果所请求的资源不可用

HTTP Status 404 - /ESA/protected/admin/list
description The requested resource is not available.

这是我的struts.xml文件:

<action name="login" class="ir.imrasta.esa.ui.action.UserAction" method="login"> 
     <result name="success">protected/admin/list</result> 
     <result name="failed">/login.jsp?login=failed</result> 
    </action> 

    <action name="/protected/admin/list" class="ir.imrasta.esa.ui.action.ManagerAction" method="list"> 
     <result name="success">/protected/admin/list.jsp</result> 
    </action> 

看到<result name="success">/protected/admin/list</result>在上面的代码。如果我改变它与一个JSP页面,它工作正常。

更新2013年7月20日:

的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_9" 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"> 

<display-name>Educational System Application</display-name> 

<filter> 
    <filter-name>loginFilter</filter-name> 
    <filter-class>ir.imrasta.esa.ui.filter.LoginFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>loginFilter</filter-name> 
    <url-pattern>/protected/*</url-pattern> 
</filter-mapping> 

<filter> 
    <filter-name>struts2</filter-name> 
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
</filter> 
<filter-mapping> 
    <filter-name>struts2</filter-name> 
    <url-pattern>/*</url-pattern> 
</filter-mapping> 

<welcome-file-list> 
    <welcome-file>index.html</welcome-file> 
</welcome-file-list> 

的struts.xml:

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

<constant name="struts.devMode" value="true" /> 
<constant name="struts.custom.i18n.resources" value="languages" /> 

<package name="default" namespace="/" extends="struts-default"> 

    <default-action-ref name="index" /> 

    <global-results> 
     <result name="error">/error.jsp</result> 
    </global-results> 

    <global-exception-mappings> 
     <exception-mapping result="error" exception="java.lang.Exception"/> 
     <exception-mapping result="error" exception="ir.imrasta.esa.bll.exceptions.DataSourceException"/> 
     <exception-mapping result="error" exception="ir.imrasta.esa.bll.exceptions.DecryptionException"/> 
    </global-exception-mappings> 

    <action name="index"> 
     <result>/index.jsp</result> 
    </action> 

    <action name="login" class="ir.imrasta.esa.ui.action.UserAction" method="login"> 
     <result name="success">protected/admin/list</result> 
     <result name="failed">/login.jsp?login=failed</result> 
    </action> 

    <action name="/protected/admin/list" class="ir.imrasta.esa.ui.action.ManagerAction" method="list"> 
     <result name="success">/protected/admin/home.jsp</result> 
    </action> 

</package> 

<!-- Add packages here --> 

</struts> 

loginFilter:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException{ 
    HttpServletRequest req=(HttpServletRequest) request; 
    HttpSession session=req.getSession(); 
    User user=(User)session.getAttribute(Constants.SESSION_USER); 
    if (user!=null){ 
     chain.doFilter(request, response); 
    }else{ 
     RequestDispatcher dispatcher=req.getRequestDispatcher("/login.jsp"); 
     dispatcher.forward(request, response); 
    } 
} 
+0

你应该发布'web.xml',项目结构,而不难给你正确的答案。 –

+0

我更新了我的帖子。这够了吗? –

+0

不,现在您必须发布'LoginFilter'的源代码或将其从Web配置中移除并重新提出问题。 –

回答

0

查看即使您所指的动作类也需要在struts.xml中映射,您得到的404的原因是您正在查找的动作类未在struts中找到任何映射

+0

在上面的代码中,我有2个动作映射。首先是当用户输入用户名和密码并单击登录按钮时运行的登录。在这里你可以看到在第二个动作中定义的/protected/admin/list'。 –

0

为了重定向到另一个操作,您需要使用redirectAction结果类型。

<action name="login" class="ir.imrasta.esa.ui.action.UserAction" method="login"> 
    <result name="success" type="redirectAction">protected/admin/list</result> 
    <result name="failed">/login.jsp?login=failed</result> 
</action> 

并且在操作中斜杠默认情况下不允许使用名称。要允许在动作名称中使用斜杠,您需要在struts.xml文件中将struts.enable.SlashesInActionNames设置为true。

<constant name="struts.enable.SlashesInActionNames" value="true" /> 
+0

谢谢。但在知道我解决它与不同的方式我使用链 –

+0

@RasoulTaheri:你到底是什么,什么是不工作? –

+0

我登录后的应用程序。我会转发给受保护的/管理员/列表操作。但网络服务器说没有这条路。我把这个动作放在另一个包中,并使用''。它现在很好用。 –