action类:
package struts;import com.opensymphony.xwork2.ActionSupport;public class HelloAction extends ActionSupport{
 private String message;public String getMessage() {
return message;
}public void setMessage(String message) {
this.message = message;
}
 public String execute(){
 if(this.message.equals("")||this.message==null){
 message="请输入问候语";
 }
 return "success";
 }
}
struts。mxl配置:
  <?xml version="1.0" encoding="UTF-8" ?> 
  <!DOCTYPE struts (View Source for full doctype...)> 
- <struts>
- <package name="com" extends="struts-default">
- <action name="hello" class="struts.HelloAction">
  <result name="success">/hello.jsp</result> 
  </action>
  </package>
  </struts>
显示的jsp:
<%@page contentType="text/html;charset=GBK" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title></title>  </head>
  
  <body>
<s:property value="message"/>
<s:form action="hello">
<s:textfield name="message" label="问候语" value=""/>
<s:submit value="提交"/>
</s:form>
  </body>
</html>
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">
- <filter>
  <filter-name>struts2</filter-name> 
  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
  </filter>
- <filter-mapping>
  <filter-name>struts2</filter-name> 
  <url-pattern>/*</url-pattern> 
  </filter-mapping>
- <welcome-file-list>
  <welcome-file>index.jsp</welcome-file> 
  </welcome-file-list>
- <login-config>
  <auth-method>BASIC</auth-method> 
  </login-config>
  </web-app>
 
当我点击提交时出现错误:
HTTP Status 404 - No result defined for action struts.HelloAction and result success--------------------------------------------------------------------------------type Status reportmessage No result defined for action struts.HelloAction and result successdescription The requested resource (No result defined for action struts.HelloAction and result success) is not available.
--------------------------------------------------------------------------------Apache Tomcat/6.0.20
  求前辈解答啊   泪奔

解决方案 »

  1.   

    <s:form action="hello">
    改成
    <s:form action="/hello">
      

  2.   

    <package name="com" extends="struts-default" namespace="/">
    namespace="/" 填上试试
      

  3.   

    你的这个jsp路径是在哪里的 ? 是在 WebContent或者WebRoot的下面吗?
      

  4.   

    嗯,有没有引入那六个jar包看看……
      

  5.   

    我用myeclipse8.5做的   加了add struts。。
      

  6.   

    页面提交action要改为 /hello.action