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

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

问题描述

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

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

找不到 Struts 调度程序.这通常是由于使用没有关联过滤器的 Struts 标签造成的.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");
}

说明:

错误清楚地表明

这通常是由于使用没有关联过滤器的 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天全站免登陆