日期:2014-05-17 浏览次数:20751 次
package message;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class for Servlet: AddMessageServlet
*
*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;
public class AddMessageServlet extends HttpServlet {
private Connection con;
public void doGet(HttpServletRequest request ,HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
String name = request.getParameter("name");
String title = request.getParameter("title");
String email=request.getParameter("email");
String content = request.getParameter("content");
if(name==null)
name = "";
if(title==null)
title = "";
if(content==null)
content = "";
if(email==null)
email="";
try
{
//此处有错误?请分析其产生的原因及,如何修改,注意要用构造函数
PreparedStatement stm=con.prepareStatement("insert into message values(?,?,?,?,?)");//此处的con值为空,我找到了,但是,要如何修改呢?及产生的原因???????????
stm.setString(1,title);
stm.setString(2,name);
stm.setDate(3,new java.sql.Date(new java.util.Date().getTime()));
if((email).length()==0)
&nb