<%@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+"/";
%>
jsp:
<!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>
struts.xml配置:
  <?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="com.struts2.hello.HelloAction">
  <result name="success">/hello.jsp</result> 
  </action>
  </package>
  </struts>
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";
 }
}
当我点击提交是出现错误,改怎么解决????前辈赐教啊 ,刚学s就遇到问题了,心都碎了

解决方案 »

  1.   

    public String execute(){
    System.out.println("---------------") ; //看看程序有没有进入到这里,如果没有进入检查你的web.xml看看 ,进入了检查你的struts.xml
    if(this.message.equals("")||this.message==null){
    message="请输入问候语";
    }
      

  2.   

    1.<s:property value="%{message}"/>2.<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>  
    改成<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    3.<s:form action="hello">
    里边加上一个method