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>
-------------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>
解决方案 »
- 在生成报表的时候出错
- 问一个关于struts中关于action验证validation的问题!
- 在MyEclipse中怎么配置websphere5.1,就不信没人会了
- 准备学J2EE,但是不知道从那里下手,希望各位高手给点建议!谢谢!
- tomcat能正常启动,服务也正常,可就是有严重警告
- struts+hibernate+tomcat中的事务处理!
- 今天考试用JBuilder8遇到些问题?
- 一个java程序运行出现的问题!帮忙看看!
- 请叫jboss下的cmr问题,急啊,我所有的分都给了
- 关于ejbSelect方法和findByXXX方法的区别?
- Eclipse问题
- Java servlet问题,初学请教~~
换成<input type="text" name ="model.msg"></input>
为什么需要写成这样啊?只写msg,model为什么不能自动得到值?
{
private T model;
public T getModel() {
return model;
} public void setModel(T model) {
this.model = model;
}
}
<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>
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>