如何通过使用JavaScript函数重定向到Struts2中的另一个JSP页面 [英] How to redirect to another jsp page in Struts2 by using JavaScript function

查看:85
本文介绍了如何通过使用JavaScript函数重定向到Struts2中的另一个JSP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在打开BeforeLogin页面时使用JavaScript函数将jsp重定向到另一个jsp页面.但是我收到以下错误消息.

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.

找不到Struts调度程序.这通常是由于使用不带相关过滤器的Struts标记引起的.只有在请求通过其Servlet过滤器传递请求时,Struts标记才可用,该Servlet过滤器会初始化该标记所需的Struts调度程序.

The Struts dispatcher cannot be found. This is usually caused by using Struts tag without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.

我不确定该怎么办.

BeforeLogin.jsp:

function newpage(){
    window.open("Login.jsp");
}

<body onLoad="goNewWin()">
<a href="BeforeLogin.jsp">click here to login</a>
</body>

Login.jsp:

<%@ taglib prefix="s" uri="/struts-tags" %>

<html>
<head>
<title>
   <s:text name="Login"/>
</title>
</head>
<body> ..... </body>

web.xml:

<filter>
    <filter-name>DispatcherFilter</filter-name>
    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>DispatcherFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

struts.xml:

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

<action name="login" class="com.action.LogonAction">
        <result name="input">Login.jsp</result>
</action>

推荐答案

创建无效的结果并使用它代替JSP.

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");
}

说明:

错误清楚地表明了这一点

The error clearly says that

这通常是由于使用Struts标记而没有关联的过滤器

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

这意味着您内部有一个JSP和Struts标记,但是此JSP未被过滤器使用,因为它可能是一个欢迎文件,即index.jsp,错误代码文件(即404.jsp),在web.xml.

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.

在涉及映射到该资源的任何过滤器或Servlet之前,这些资源由Web服务器处理.

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

通常,欢迎文件包含一个指向有效操作的重定向代码,然后将其分配给可以具有Struts标记的JSP. 不要在您的应用程序中直接使用JSP,而应使用操作.

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.

这篇关于如何通过使用JavaScript函数重定向到Struts2中的另一个JSP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆