ssh框架是自己用eclipse搭建的,断点调试时发现model里的msg的值为null,不知道为什么画面输入了值却传不到model中?求高手提示哈。
-------------ACTION类---------------
public class TESTACTION extends ActionSupport {
private static final long serialVersionUID = 1L; private TESTMODEL model;
@Override
public String execute() throws Exception {
if ("badBoy".equals(this.model.getMsg())){
return ActionSupport.SUCCESS;
}else
{
return ActionSupport.ERROR;
}
} public TESTMODEL getModel() {
return model;
} public void setModel(TESTMODEL model) {
this.model = model;
}
}
----------model类---------------------
public class TESTMODEL {
private String msg; public String getMsg() {
return msg;
} public void setMsg(String msg) {
this.msg = msg;
}}
-----------------jsp-----------------
<%@ page contentType="text/html; charset=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=windows-31j">
<title>TestCase</title>
</head>
<body>
<s:form action="helloAction" method="post">
<input type="text" name ="msg"></input> <input type="submit" name ="submit" value="commit"></input> </s:form></body>
</html>

解决方案 »

  1.   

    要通过TESTACTION 类定义一个对象,让对象调用getMsg()才能取到值。
      

  2.   

    这里<input type="text" name ="msg"></input>
    换成<input type="text" name ="model.msg"></input>
      

  3.   


    为什么需要写成这样啊?只写msg,model为什么不能自动得到值?
      

  4.   

    strut的配置文件发上来看看,按理来说用eclipse搭的话JSP的很多标签都会自己生成的
      

  5.   

    TESTACTION<T extends TESTMODEL> extends ActionSupport implements ModelDriven<T>
    {
            private T model;
    public T getModel() {
    return model;
    } public void setModel(T model) {
    this.model = model;
    }
    }
      

  6.   

    struts.xml
    <struts>
        <package name="firstStruts" namespace="/" extends="struts-default">
            <action name="helloAction"  class="testAction">
            <result name="success">
    /hello.jsp
    </result>
    <result name="error">
    /error.jsp
    </result>
            </action>
        </package>
    </struts>
    web.xml
      <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> <!-- 指明spring配置文件处 -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/applicationContext.xml</param-value>
        </context-param><!-- applicationContext.xml -->
         <listener>
             <listener-class>
                 org.springframework.web.context.ContextLoaderListener
             </listener-class>
         </listener>
      

  7.   

    applicationContext.xml <bean id="testAction" class="cn.co.action.TESTACTION"
    scope="prototype">
    <property name="model" ref="testModel" />
    <property name="service" ref="testService" />
    </bean> <bean id="testModel" class="cn.co.model.TESTMODEL"
    scope="prototype">
    </bean> <bean id="testService" class="cn.co.service.impl.TESTSERVICEImpl"
    scope="prototype">
    </bean>