类2
import java.io.UnsupportedEncodingException;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.kucheTV.dao.DAOFactory;
import com.kucheTV.dao.MaterialDAO;
import com.kucheTV.domain.Material;
import com.kucheTV.struts.form.MaterialForm;;
public class AddMaterial extends Action {
private MaterialDAO materDao; public MaterialDAO getMaterialDAO() {
return DAOFactory.getInstance().createMaterialDAO();
} public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// ActionMessages errors = new ActionMessages(); MaterialForm materForm = (MaterialForm) form; materDao = this.getMaterialDAO();
Material mater =new Material();
try {
mater.setMaid( new String(materForm.getMaid().getBytes("ISO-8859-1"),"GB2312") );
mater.setMaterial( new String(materForm.getMaterial().getBytes("ISO-8859-1"),"GB2312"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} if (materDao.saveMaterial(mater)) {
return (mapping.findForward("success"));
}else{
return (mapping.getInputForward());
}
}}
import java.io.UnsupportedEncodingException;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.kucheTV.dao.DAOFactory;
import com.kucheTV.dao.MaterialDAO;
import com.kucheTV.domain.Material;
import com.kucheTV.struts.form.MaterialForm;;
public class AddMaterial extends Action {
private MaterialDAO materDao; public MaterialDAO getMaterialDAO() {
return DAOFactory.getInstance().createMaterialDAO();
} public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// ActionMessages errors = new ActionMessages(); MaterialForm materForm = (MaterialForm) form; materDao = this.getMaterialDAO();
Material mater =new Material();
try {
mater.setMaid( new String(materForm.getMaid().getBytes("ISO-8859-1"),"GB2312") );
mater.setMaterial( new String(materForm.getMaterial().getBytes("ISO-8859-1"),"GB2312"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} if (materDao.saveMaterial(mater)) {
return (mapping.findForward("success"));
}else{
return (mapping.getInputForward());
}
}}
解决方案 »
- 求助:Struts2
- 处理前后空格,使用trim()的困惑?
- 如何获取某标签中子项个数??
- 高手请进!我现在在java代码中打开一个excel文件后,不能Forward到指定的jsp画面了
- 请高手帮忙解决CachedRowSet的别名问题
- 天乙社区采用UTF-8的编码,源码也要用UTF-8来编译。这是某位大虾的话,在eclipse中怎样设置?
- window.form1和document.Form1有什么区别呢??
- oracle 在 red hat 9 上不能连接的问题!!!!
- 送分题!关于JSP传参数
- 求助各位大佬,layui框架,按钮根据两个表数据比较,实现显示相应按钮怎么做啊?
- TOMCAT做服务器,JSP文件不能命名为中文,请问这个怎么处理
- 能否使程序自动为数据库动态新建的表起名字
<%@ page import="java.sql.*,com.kucheTV.service.*"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />
<title>增加材料</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<body>
<p>
<%
/*
String admin_id = (String) session.getAttribute("id");
if (admin_id == null) {
response.sendRedirect("login.jsp");
}
*/
%>
</p>
<p align="center">
新增材料
</p>
<form method="post" action="/kucheTV/addMaterial.do">
<table width="49%" height="50" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="48%">
材料编号
</td>
<td width="52%">
<html:text property="maid" value="" />
</td>
<tr>
<td width="48%">
材料名称
</td>
<td width="52%">
<html:text property="material" value="" />
</td>
</tr>
<tr>
<td width="48%">
材料数量
</td>
<td width="52%">
<html:text property="manumber" value="" />
</td>
</tr>
</table>
<p align="center">
<input type="submit" name="Submit" value="提交">
</p>
</form>
<a href="getMaterial.jsp"><<Back </a>
</body>
</html:html>
public boolean saveMaterial(Material mater) {
// TODO Auto-generated method stub
try {
Session s = HibernateUtil.currentSession();
HibernateUtil.beginTransaction();
s.saveOrUpdate(mater);
//用save()试试..
System.out.println("save Material maid =" + mater.getMaid());
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
return true;
} catch (HibernateException e) {
log.fatal(e);
}
return false; } } 因为saveOrUpdate 方法会根据 unsave-value 去判断这个对象是更新还是保存 如果 unsave-value不是你的期望值就要手动设置.
恩,看你hbm.xml里有没设置unsavevalue