0

我正在尝试创建从一页到另一页的链接。我的主页是:enter-protein.jsp,我想在此页面中创建一个链接,当任何人单击该链接时,该链接将转发到另一个页面。我已经创建了链接,但它没有正确转发到该页面并且出现错误。创建应用程序时出现以下错误:

Sep 01, 2013 7:21:00 PM com.opensymphony.xwork2.util.logging.jdk.JdkLogger error
SEVERE: Exception occurred during processing request: There is no Action mapped for namespace [/] and action name [enter-goal] associated with context path [/ExampleTracker].
There is no Action mapped for namespace [/] and action name [enter-goal] associated with context path [/ExampleTracker]. - [unknown location]
    at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
    at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
    at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
    at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:553)
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

我的代码如下:

输入-protein.java

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
 <%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<a href="<s:url action="enter-goal" />"> Edit Goal</a>

</body>
</html>

enter-goal.jsp 文件是:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

 <%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Goal format page</title>
</head>
<body>

    <s:form>
        <h1>Goal amount:</h1>
        <s:textfield name="goal"/>
        <s:submit value="Save" />
    </s:form>

</body>
</html>

你能帮我在哪里改变,这样错误就会消失。

4

1 回答 1

0

问题是 s:url 标签。

<a href="<s:url action="enter-goal" />"> Edit Goal</a>

服务器端标签告诉 Struts 返回一个 URL 到一个名为 'enter-goal' 的动作(MVC 术语中的控制器)。动作在 struts 配置文件中定义(或者可能是注释,不确定?)。

要链接到 JSP,只需直接指向 JSP。不需要服务器端标签:

<a href="enter-goal.jsp"> Edit Goal</a>
于 2013-09-02T00:41:44.237 回答