我在NetBeans 7.2.1中嘗試我的第一個應用程序在struts 2.3.16上。它在輸入URL時顯示以下錯誤 - http://localhost:8080/TestStruts/Test.action
(有一個Test.jsp
頁面)。沒有爲命名空間[/]映射的動作和與上下文路徑[/ TestStruts]關聯的動作名稱[Test]。 - [未知位置]
WARNING: Could not find action or result: /TestStruts/Test.action
There is no Action mapped for namespace [/] and action name [Test] associated with context path [/TestStruts]. - [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:37)
at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552)
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:472)
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:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
的Test.jsp
頁:
<s:form namespace="/TestStruts" action="test">
<table border="0" class="">
<tr>
<td>
<s:textfield id="name" name="name" label="Enter your name"/>
</td>
</tr>
<tr>
<td>
<s:textfield id="email" name="email" label="Enter your email"/>
</td>
</tr>
<tr>
<td></td>
<td><s:submit value="Submit"/></td>
</tr>
</table>
</s:form>
動作類:
package actions;
import com.opensymphony.xwork2.ActionSupport;
public final class TestAction extends ActionSupport
{
private static final String SUCCESS = "success";
private String name;
private String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String execute() throws Exception
{
System.out.println("name = "+name);
System.out.println("email = "+email);
return SUCCESS;
}
}
的strtus.xml
文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.custom.i18n.resources" value="myapp" />
<package name="test" namespace="/TestStruts" extends="struts-default">
<action name="test" class="actions.TestAction" method="execute">
<result name="success">/Test.jsp</result>
</action>
</package>
</struts>
的web.xml
文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
除了罐子春的文件,我已經添加了以下jar文件到classpath中。
- 公地BeanUtils的-1.8.0.jar
- 公地鏈1.2.jar
- 公地集合-3.1.jar
- 公地消化器-2.0.jar
- commons-文件上傳-1.3.jar
- 公地IO-2.2.jar
- 公地lang3-3.1.jar
- 公地郎2.4.jar 個
- 共享記錄-1.1.3.jar
- 共享記錄-API-1.1.jar
- 公地驗證-1.3.1.jar
- freemarker的-2.3.19.jar
- javassist- 3.11.0.GA.jar
- OGNL-3.0.6.jar
- struts2的核 - 2.3.16.jar
- struts2的 - 彈簧 - 插件-2.3.16.jar
- XWork的-芯 - 2.3.16.jar
當URL被從.action
像http://localhost:8080/TestStruts/Test.jsp
改變爲.jsp
,它顯示以下的警告。
Dec 22, 2013 9:00:44 PM org.apache.struts2.components.ServletUrlRenderer warn
WARNING: No configuration found for the specified action: 'test' in namespace: '/TestStruts'. Form action defaulting to 'action' attribute's literal value.
Dec 22, 2013 9:00:45 PM org.apache.struts2.components.ServletUrlRenderer warn
WARNING: No configuration found for the specified action: 'test' in namespace: '/TestStruts'. Form action defaulting to 'action' attribute's literal value.
我錯過了什麼?
我試過這個URL - 「http:// localhost:8080/TestStruts/TestStruts/test.action」,但它給出了這個警告警告:找不到動作或結果:/TestStruts/TestStruts/test.action 沒有爲動作名稱測試映射的動作。 - [未知位置]'阻止顯示頁面。 – Tiny
更改此「<!DOCTYPE struts PUBLIC \t」 - // Apache Software Foundation // DTD Struts Configuration 2.3 // EN「 \t」http://struts.apache.org/dtds/struts-2.3.dtd「> ' –
改變了它,但沒有運氣。有沒有我可能錯過的圖書館? – Tiny