很简单,需要注意的是:
在FormBean里 Integer state = new Integer(2);这样初始化和在配置文件中这样初始化:
<form-property initial="2" name="state" type="java.lang.Integer" />
是不起冲突的,配置文件的优先级更高,实际上这里配不配都是一样的
假设struts-config.xml中本来是这样:
<form-bean name="discussForm" type="org.apache.struts.action.DynaActionForm">
<form-property initial="2" name="state" type="java.lang.Integer" />
<form-property name="staffId" type="java.lang.Integer" />
<form-property name="title" type="java.lang.String" />
<form-property name="messageContent" type="java.lang.String" />
<form-property initial="false" name="needReply" type="java.lang.Boolean" />
<form-property name="messageId" type="java.lang.String" />
<form-property name="receiverId" type="java.lang.Integer" />
<form-property name="reply" type="java.lang.Boolean" />
<form-property name="file1" type="org.apache.struts.upload.FormFile" />
<form-property name="file2" type="org.apache.struts.upload.FormFile" />
<form-property name="file3" type="org.apache.struts.upload.FormFile" /> </form-bean>
只改其引用类型:org.apache.struts.action.DynaActionForm,改成com.message.MessageActionForm
则该Form为:
import org.apache.struts.action.ActionForm;
import org.apache.struts.upload.FormFile;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MessageActionForm
extends ActionForm {
Integer state = new Integer(2);//这里也可以这么写Integer state;即可
Integer staffId;
Integer deptId;
String title;
String messageContent;
Boolean needReply = new Boolean(false);//Boolean needReply;也可以这么写
String messageId;
Integer receiverId;
Boolean reply;
FormFile file1;
FormFile file2;
FormFile file3;
Log log = LogFactory.getLog(MessageActionForm.class);
public MessageActionForm() {
}
public void reset(ActionMapping mapping, HttpServletRequest request) {
try {
request.setCharacterEncoding("GBK");
}
catch (UnsupportedEncodingException ex) {
log.info("encoding error! ", ex);
}
}
public FormFile getFile1() {
return file1;
}
public void setFile1(FormFile file1) {
this.file1 = file1;
}
public FormFile getFile2() {
return file2;
}
public void setFile2(FormFile file2) {
this.file2 = file2;
}
public FormFile getFile3() {
return file3;
}
public void setFile3(FormFile file3) {
this.file3 = file3;
}
public String getMessageContent() {
return messageContent;
}
public void setMessageContent(String messageContent) {
this.messageContent = messageContent;
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
public Boolean getNeedReply() {
return needReply;
}
public void setNeedReply(Boolean needReply) {
this.needReply = needReply;
}
public Integer getReceiverId() {
return receiverId;
}
public void setReceiverId(Integer receiverId) {
this.receiverId = receiverId;
}
public Boolean getReply() {
return reply;
}
public void setReply(Boolean reply) {
this.reply = reply;
}
public Integer getStaffId() {
return staffId;
}
public void setStaffId(Integer staffId) {
this.staffId = staffId;
}
public Integer getState() {
return state;
}
public void setState(Integer state) {
this.state = state;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}