How to redirect to another jsp page in Struts2 by using JavaScript function

前端 未结 2 1080
野的像风
野的像风 2021-01-16 11:59

I want to redirect my jsp to another jsp page by using JavaScript function when I open the BeforeLogin page. But I got below error message.

相关标签:
2条回答
  • 2021-01-16 12:27

    This error is created because you're calling a JSP that is trying to use Struts tags without having passed through an action first, and hence not finding the required underlying structure.

    Struts2 is an MVC framework, which design implies that a new request must pass through a (C)ontroller (the action) and then be rendered through a (V)iew (the JSP).

    You must avoid calling JSPs directly, you must instead call the login action, that after its execution will dispatch the login JSP.

    window.open("login.action");
    
    0 讨论(0)
  • 2021-01-16 12:39

    Create actionless result and use it instead of JSP.

    struts.xml:

    <action name="showLogin">
            <result>Login.jsp</result>
    </action>
    

    JS:

    function newpage(){
        window.open("showLogin");
    }
    

    Explanation:

    The error clearly says that

    This is usually caused by using Struts tags without the associated filter

    it means that you have a JSP and Struts tags inside it, but this JSP is not used by the filter, because it could be a welcome file, i.e. index.jsp, error code file, i.e. 404.jsp, configured in the web.xml.

    These resources are handled by the web server before any filter or servlet mapped to the resource is being involved.

    Usually welcome files contain a redirect code to a valid action which then dispatch to a JSP that can have Struts tags. Don't use JSPs directly in your application, use actions instead.

    0 讨论(0)
提交回复
热议问题