问题描述
我想在打开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.
我不确定该怎么办.
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
这意味着您内部有一个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页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!