0

I have a login page and a login action. When user logins action return "success" result. and it must go to another action. But I get the following error:

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

this is my struts.xml file :

    <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>  

see <result name="success">/protected/admin/list</result> in above code. if i change it with a jsp page it work fine.

update 2013/07/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);
    }
}
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Rasoul Taheri
  • 802
  • 3
  • 16
  • 32

2 Answers2

0

See even the action class which you are referring too also needed to be mapped in struts.xml, the reason you are getting 404 is that the action class which you are finding is not having any mapping found in struts

Kalaiarasan Manimaran
  • 1,598
  • 1
  • 12
  • 18
  • in above code i have 2 action mapping. the first is login that run when user enter username & password and click login button. in this you can see `/protected/admin/list` that defined in second action. – Rasoul Taheri Jul 20 '13 at 10:54
0

In order to redirect to another action you need to use redirectAction result type.

<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>

And slashes in action names are not allowed by default. To allow slashes in action names you need to set struts.enable.SlashesInActionNames constant to true in struts.xml file.

<constant name="struts.enable.SlashesInActionNames" value="true" />
Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • thanks you. but in the know i solve it with defferent way i use chain – Rasoul Taheri Jul 20 '13 at 13:47
  • @RasoulTaheri: What exactly are you using and what is not working? – Aleksandr M Jul 20 '13 at 13:48
  • after i logged in the app. i will it forward to protected/admin/list action. but web server says there is not this path. i put this action in the another package and use ``. it work good now. – Rasoul Taheri Jul 20 '13 at 13:52
  • @RasoulTaheri: That means that you probably haven't set `struts.enable.SlashesInActionNames` constant. And don't use `chain` result if don't know what you are doing. For action redirection there is `redirectAction` result type. – Aleksandr M Jul 20 '13 at 13:56