首先把页面需要的文件引入:js、 img、css、system.文件夹。地址为:http://download.csdn.net/download/zl544434558/6419869
第一,编写与页面对应的form(ElecTextForm.java) 从页面传递过来的值都为String类型
public class ElecTextForm {
private String textID;
private String textName;
private String textDate;
private String textRemark;
public String getTextID() {
return textID;
}
public void setTextID(String textID) {
this.textID = textID;
}
public String getTextName() {
return textName;
}
public void setTextName(String textName) {
this.textName = textName;
}
public String getTextDate() {
return textDate;
}
public void setTextDate(String textDate) {
this.textDate = textDate;
}
public String getTextRemark() {
return textRemark;
}
public void setTextRemark(String textRemark) {
this.textRemark = textRemark;
}
}
第二、编写web.xml文件
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
第三:编写struts.xml文件
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<constant name="struts.action.extension" value="do" />
<constant name="struts.devMode" value="true" />
<constant name="struts.ui.theme" value="simple" />
<package name="system" extends="struts-default" namespace="/system">
<action name="elexTextAction_*" class="com.evan.action.ElecTextAction"
method="{1}">
<result name="save">
/system/textAdd.jsp
</result>
</action>
</package>
</struts>
第四、编写ElecTextAction文件
package com.evan.action;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.evan.domain.ElecText;
import com.evan.form.ElecTextForm;
import com.evan.service.IElecTextService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
public class ElecTextAction extends ActionSupport implements
ModelDriven<ElecTextForm> {
private static final long serialVersionUID = 1L;
ElecTextForm elecTextForm = new ElecTextForm();
public String save() throws ParseException {
ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
IElecTextService IelecTextService = (IElecTextService) ac
.getBean(IElecTextService.SERVICENAME);
ElecText elecText = new ElecText();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = null;
try {
date = format.parse(elecTextForm.getTextDate());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
elecText.setTextDate(date);
elecText.setTextName(elecTextForm.getTextName());
elecText.setTextRemark(elecTextForm.getTextRemark());
IelecTextService.saveElecText(elecText);
System.out.println(elecText.getTextRemark());
return "save";
}
@Override
public ElecTextForm getModel() {
// TODO Auto-generated method stub
return elecTextForm;
}
}
至此三大框架搭建完毕。将项目添加到tomcat。
访问地址为:http://localhost:8081/ElecText_mysql/system/textAdd.jsp