struts问题不知道哪里错了,代码如下:
welcome.jsp:
<form action="struts.action" method="post">
请输入姓名:<input type="text" name="name"/><br>
<input type="submit" value="提交"/>
</form>
struts.xml:
<package name="default" extends="structs-default">
<action name="struts" class="org.action.strutsAction">
<result name="success">welcome.jsp</result>
<result name="error">jsp/hello.jsp</result>
<result name="input">jsp/hello.jsp</result>
</action></package>
hello.jsp:
hello<s:property value="#request.name"/>!
action类:
package org.action;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;public class strutsAction extends ActionSupport {
private String name="";
public String getName(){
return this.name;
}
public void setName(String name){
this.name=name;
}
public String execute()throws Exception{
if(!name.equals("hello world")){
Map request=(Map)ActionContext.getContext().get("request");
request.put("name",getName());
System.out.println(this.name);
return SUCCESS;
}
else return "error";
}
}web.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">
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>
<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></web-app>我用的软件是myeclipse 8.5其中总是出现No result defined for action org.action.strutsAction and result success
不知道为什么
welcome.jsp:
<form action="struts.action" method="post">
请输入姓名:<input type="text" name="name"/><br>
<input type="submit" value="提交"/>
</form>
struts.xml:
<package name="default" extends="structs-default">
<action name="struts" class="org.action.strutsAction">
<result name="success">welcome.jsp</result>
<result name="error">jsp/hello.jsp</result>
<result name="input">jsp/hello.jsp</result>
</action></package>
hello.jsp:
hello<s:property value="#request.name"/>!
action类:
package org.action;import java.util.Map;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;public class strutsAction extends ActionSupport {
private String name="";
public String getName(){
return this.name;
}
public void setName(String name){
this.name=name;
}
public String execute()throws Exception{
if(!name.equals("hello world")){
Map request=(Map)ActionContext.getContext().get("request");
request.put("name",getName());
System.out.println(this.name);
return SUCCESS;
}
else return "error";
}
}web.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">
<welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
</welcome-file-list>
<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></web-app>我用的软件是myeclipse 8.5其中总是出现No result defined for action org.action.strutsAction and result success
不知道为什么
web.xml<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
页面也设置一下。