目录结构如下:
根目录在 D:/Tomcat 6.0/webapps/Struts2
index.jsp: D:/Tomcat 6.0/webapps/Struts2/index.jsp
web.xml: D:/Tomcat 6.0/webapps/Struts2/WEB-INF/web.xml
struts.xml: D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/struts.xml
struts.properties D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/struts.properties
HelloStruts2World.class D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/hello/HelloStruts2World.classweb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd"> <filter>
<filter-name>Struts 2 filter </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<filter-mapping>
<filter-name>Struts 2 filter </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>**************************************************************************************
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="hello" extends="struts-default">
<action name="HelloStruts2World" class="hello.HelloStruts2World">
<result name="success">/index.jsp </result>
</action>
</package>
</struts>
**************************************************************************************index.jsp<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@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=UTF-8">
<title>Hello Struts 2 World Result Page </title>
</head>
<body>
<h2>Hello World! </h2>
Struts 2 Message: <s:property value="message" default="Guest." />
<s:form method="GET" action="hello/HelloStruts2World.action">
Enter your name: <s:textfield name="userName" />
<s:submit value="Submit" />
</s:form>
</body>
</html>
index.jsp可以正常显示,但是点击Submit按钮会出现错误:
There is no Action mapped for action name HelloStruts2World. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
根目录在 D:/Tomcat 6.0/webapps/Struts2
index.jsp: D:/Tomcat 6.0/webapps/Struts2/index.jsp
web.xml: D:/Tomcat 6.0/webapps/Struts2/WEB-INF/web.xml
struts.xml: D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/struts.xml
struts.properties D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/struts.properties
HelloStruts2World.class D:/Tomcat 6.0/webapps/Struts2/WEB-INF/classes/hello/HelloStruts2World.classweb.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd"> <filter>
<filter-name>Struts 2 filter </filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher </filter-class>
</filter>
<filter-mapping>
<filter-name>Struts 2 filter </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>**************************************************************************************
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="hello" extends="struts-default">
<action name="HelloStruts2World" class="hello.HelloStruts2World">
<result name="success">/index.jsp </result>
</action>
</package>
</struts>
**************************************************************************************index.jsp<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@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=UTF-8">
<title>Hello Struts 2 World Result Page </title>
</head>
<body>
<h2>Hello World! </h2>
Struts 2 Message: <s:property value="message" default="Guest." />
<s:form method="GET" action="hello/HelloStruts2World.action">
Enter your name: <s:textfield name="userName" />
<s:submit value="Submit" />
</s:form>
</body>
</html>
index.jsp可以正常显示,但是点击Submit按钮会出现错误:
There is no Action mapped for action name HelloStruts2World. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:494)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:419)
解决方案 »
- spring placeholderConfig的问题
- 建立博客数据库问题??
- struts2.x 批量提交问题
- 从刚刚插入的自增型主键表中获取主键
- 我是这么配置的连接池可是为什么出错呢??????
- 非常急,如何在HTML源码中匹配查找多行文字?
- 用过JSTL中的SQL标签的朋友来看看~!
- Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
- 求助myfaces中的tree2的用法
- 再谈Tomcta4.1.18数据源问题?
- richfaces部署不成功
- 在线等,Unable to load class for JSP
这里错误了!
直接应该是:HelloStruts2World.action
hello应该是命名空间,你的没有定义namespace="hello"配置文件添加命名空间,这样就好了:
<package name="hello" extends="struts-default" namespace="hello">
<s:form method="GET" action="HelloStruts2World">.action可以不用加的!
谢谢回答照你说的做了
可是还是一样的错误
package hello;import com.opensymphony.xwork2.ActionSupport;
public class HelloStruts2World extends ActionSupport {
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
private String message;
public String getMessage() {
return message;
}
@Override
public String execute() {
message = "Hello, " + userName + ".";
return SUCCESS;
}
}
会不会是Tomcat有什么特别的设置啊
改成
<s:form method="GET" action="HelloStruts2World.action">
才能用hello/hello/HelloStruts2World.action