当前位置: 代码迷 >> Java Web开发 >> 求教高手解题,万分感谢
  详细解决方案

求教高手解题,万分感谢

热度:502   发布时间:2010-06-27 18:33:41.0
求教高手解题,万分感谢
我在mvc模式中写入的程序出现了一个我不解的错误源代码如下:
登陆页面:addtask.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'addtask.jsp' starting page</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>
     <form action="servlet/addTask" method="post">
         安排周任务!!<br><br>
         任务编号:<input type="text" name="Iden_no"><br><br>
        任务名称: <input type="text" name="Task_name"><br><br>
        来源: <input type="text" name="Source"><br><br>
   来源类型:<input type="text" name="Source_type"><br><br>
        任务类型: <input type="text" name="Task_type"><br><br>
       任务状态: <input type="text" name="Task_state"><br><br>
        任务日期: <input type="text" name="Task_date"><br><br>
        任务描述: <input type="text" name="Task_desc"><br><br>
         <input type="submit" value="提交">
         <input type="reset" value="重置">
     </form>
  </body>
</html>

dao层:

package com.dao;
import com.po.TTask;
public interface TTaskDao {
     public void insert1(TTask t);  //新增一个任务
     public void delTask(String id);   //删除一个任务
        //修改一个任务
     public void insert(TTask n);//安排周任务
}

package com.dao.impl;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.po.TTask;
import com.util.HibSession;
public class TTaskDaoImpl {
private Session session = null;
Transaction tr = null;
  public void insert1(TTask t){
   try {
   session=HibSession.getCurrentSessoin();
    tr=session.beginTransaction();
   session.save(t);
   tr.commit();
   System.out.println("数据库连接成功!");
  } catch (HibernateException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  }
  public void delTask(String id){
   session=HibSession.getCurrentSessoin();
   tr=session.beginTransaction();
   String hql="from TTask t where t.taskId=? ";
   Query query=session.createQuery(hql);
   query.executeUpdate();
   tr.commit();
  }
  public void comto(TTask n){
   session=HibSession.getCurrentSessoin();
   tr=session.beginTransaction();
   session.save(n);
   tr.commit();
  }
  
}


servlet层:

package com.control;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.impl.TTaskDaoImpl;
import com.po.TTask;
public class addTask extends HttpServlet {
/**
  * The doGet method of the servlet. <br>
  *
  * This method is called when a form has its tag value method equals to get.
  *
  * @param request the request send by the client to the server
  * @param response the response send by the server to the client
  * @throws ServletException if an error occurred
  * @throws IOException if an error occurred
  */
public void service(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();  
   String id=request.getParameter("Iden_no");
   String name=request.getParameter("Task_name");
   String source=request.getParameter("Source");
   String source_type=request.getParameter("Source_type");
   String task_type=request.getParameter("Task_type");
   String task_state=request.getParameter("Task_state");
   String task_date=request.getParameter("Task_date");
   
   String task_desc=request.getParameter("Task_desc");
   TTask t1=new TTask();
   t1.setIdenNo(id);
   t1.setTaskName(name);
   t1.setSource(source);
   t1.setSourceType(source_type);
   t1.setTaskType(task_type);
   t1.setTaskState(task_state);
   t1.setTaskDate(task_date);
   t1.setTaskDesc(task_desc);
   TTaskDaoImpl t=new TTaskDaoImpl();
   t.insert1(t1);
   request.getRequestDispatcher("/jsp/success1.jsp").forward(request, response);

  
}
}
been层:
package com.po;
import java.util.HashSet;
import java.util.Set;
/**
* TTask entity. @author MyEclipse Persistence Tools
*/
public class TTask implements java.io.Serializable {
// Fields
private String taskId;
private String idenNo;
private String source;
private String sourceType;
private String taskName;
private String taskType;
private String taskState;
private String taskDate;
private String taskDesc;
private Set TPlans = new HashSet(0);
// Constructors
/** default constructor */
public TTask() {
}
/** minimal constructor */
public TTask(String taskId, String idenNo, String source,
   String sourceType, String taskName, String taskType,
   String taskState) {
  this.taskId = taskId;
  this.idenNo = idenNo;
  this.source = source;
  this.sourceType = sourceType;
  this.taskName = taskName;
  this.taskType = taskType;
  this.taskState = taskState;
}
/** full constructor */
public TTask(String taskId, String idenNo, String source,
   String sourceType, String taskName, String taskType,
   String taskState, String taskDate, String taskDesc, Set TPlans) {
  this.taskId = taskId;
  this.idenNo = idenNo;
  this.source = source;
  this.sourceType = sourceType;
  this.taskName = taskName;
  this.taskType = taskType;
  this.taskState = taskState;
  this.taskDate = taskDate;
  this.taskDesc = taskDesc;
  this.TPlans = TPlans;
}
// Property accessors
public String getTaskId() {
  return this.taskId;
}
public void setTaskId(String taskId) {
  this.taskId = taskId;
}
public String getIdenNo() {
  return this.idenNo;
}
public void setIdenNo(String idenNo) {
  this.idenNo = idenNo;
}
public String getSource() {
  return this.source;
}
public void setSource(String source) {
  this.source = source;
}
public String getSourceType() {
  return this.sourceType;
}
public void setSourceType(String sourceType) {
  this.sourceType = sourceType;
}
public String getTaskName() {
  return this.taskName;
}
public void setTaskName(String taskName) {
  this.taskName = taskName;
}
public String getTaskType() {
  return this.taskType;
}
public void setTaskType(String taskType) {
  this.taskType = taskType;
}
public String getTaskState() {
  return this.taskState;
}
public void setTaskState(String taskState) {
  this.taskState = taskState;
}
public String getTaskDate() {
  return this.taskDate;
}
public void setTaskDate(String taskDate) {
  this.taskDate = taskDate;
}
public String getTaskDesc() {
  return this.taskDesc;
}
public void setTaskDesc(String taskDesc) {
  this.taskDesc = taskDesc;
}
public Set getTPlans() {
  return this.TPlans;
}
public void setTPlans(Set TPlans) {
  this.TPlans = TPlans;
}
}

显示页面层:

<%@ page language="java" import="java.util.*"  pageEncoding="gbk"%>
<%@ page import="com.po.TTask" %>
<%@ page import="com.po.TPlan" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>更新任务</title>
</head>
<link rel="stylesheet" type="text/css" href="mack.css">
<body>
<div class="additem">
<center>
<br /><font size="+2">
更新任务</font>
<br />
<div style="text-align:right;width:330px;">
<%
     TTask task=new TTask();
     TPlan plan=new TPlan();
  %>
<table width="850px" border="1">
  <tr>
    <td>任务标示号</td>
   
    <td>任务名称</td>
    <td>任务来源</td>
    <td>任务来源类型</td>
    <td>任务类型</td>
    <td>任务状态</td>
    <td>任务日期</td>
    <td>任务描述</td>
    <td>任务进度描述</td>
    <td><br /></td><td><br /></td><td></td>
  </tr>
  <%
      response.setContentType("text/html;charset=gbk");
     List<TTask> lst=(List<TTask>)request.getAttribute("lsttask");
     if(lst==null)
     out.println("没有记录");
     else
     System.out.println("size="+lst.size());
     for(int i=0;i<lst.size();i++){
       task=lst.get(i);
       System.out.println("id="+task.getTaskId());
     }
   %>
  <tr>
    <td><%=task.getIdenNo()%></td>
    <td><%=task.getTaskName() %></td>
    <td><%=task.getSource() %></td>
    <td><%=task.getSourceType() %></td>
    <td><%=task.getTaskType() %></td>
    <td><%=task.getTaskState() %></td>
    <td><%=task.getTaskDate() %></td>
    <td><%=task.getTaskDesc() %></td>
    <td><%=plan.getStackPlanDesc() %></td>
    <td><a href="#">删除</a></td>
    <td><a href="#">修改</a></td>
    <td><a href="#">添加</a></td>
  </tr>

</table>
</div>
</center>
</div>
</body>
</html>

在这个页面中抛出了一个500异常提示如下::


2010-6-27 18:15:46 org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0\bin;F:\apachetomcat6.0.18\apache-tomcat-6.0.18\bin
2010-6-27 18:15:46 org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2010-6-27 18:15:46 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 664 ms
2010-6-27 18:15:46 org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2010-6-27 18:15:46 org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.18
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
2010-6-27 18:15:49 org.apache.catalina.core.ApplicationContext log
信息: Loading Spring root WebApplicationContext
2010-6-27 18:15:56 org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2010-6-27 18:15:56 org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2010-6-27 18:16:02 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts-default.xml]
2010-6-27 18:16:03 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts-plugin.xml]
2010-6-27 18:16:03 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
信息: Parsing configuration file [struts.xml]
2010-6-27 18:16:03 org.apache.struts2.config.Settings getLocale
警告: Settings: Could not parse struts.locale setting, substituting default VM locale
2010-6-27 18:16:03 com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory <clinit>
信息: Setting DefaultObjectTypeDeterminer as default ...
2010-6-27 18:16:03 org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2010-6-27 18:16:04 org.apache.jk.common.ChannelSocket init
信息: JK: ajp13 listening on /0.0.0.0:8009
2010-6-27 18:16:04 org.apache.jk.server.JkMain start
信息: Jk running ID=0 time=0/63  config=null
2010-6-27 18:16:04 org.apache.catalina.startup.Catalina start
信息: Server startup in 17328 ms
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate:
    insert
    into
        contestdb.t_task
        (iden_no, source, source_type, task_name, task_type, task_state, task_date, task_desc, task_id)
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?)
org.hibernate.exception.DataException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:77)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:254)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1001)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:339)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.dao.impl.TTaskDaoImpl.insert1(TTaskDaoImpl.java:19)
at com.control.addTask.service(addTask.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.util.StringFi.doFilter(StringFi.java:22)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.BatchUpdateException: Data too long for column 'task_state' at row 1
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1492)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:247)
... 25 more

希望高手们给个解决办法,在此先谢谢了
搜索更多相关主题的帖子: 解题  感谢  

----------------解决方案--------------------------------------------------------
异常的倒数第四行
Caused by: java.sql.BatchUpdateException: Data too long for column 'task_state' at row 1

你看看你输入的这个字段的长度是不是和数据库的设置冲突了,提示过长。

----------------解决方案--------------------------------------------------------
这种什么类型都是用String的方式本来就不是很可取,建议不同的内容采用更合适的类型,在存入bean的时候可以做一下类型转换,可以避免错误继续向后延伸。
----------------解决方案--------------------------------------------------------
回复 楼主 夏世
这个问题解决了      我把数据库的字段长度看错了    程序运行出来了       还有我现在在为那个乱码问题发愁    我不知道是哪里错了    从数据库得到的字段名都是乱码    我不知道该如何解决了   这个问题搞了几天了  可以帮我看下问题吗
----------------解决方案--------------------------------------------------------
看看你的页面:
<%@ page language="java" import="java.util.*"  pageEncoding="gbk"%>
<%@ page import="com.po.TTask" %>
<%@ page import="com.po.TPlan" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>更新任务</title>
说明目前前台页面编码和你的服务器端响应所使用的编码是不同的,你可以将两者改成一样再试试.
----------------解决方案--------------------------------------------------------
  相关解决方案