三大框架整合ssh(四)-----controller层及页面

首先把页面需要的文件引入: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


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值