关于Servlet 开发的出现的错误?谁能帮我看看:在这先谢谢了!!!!

shangyongjun 2004-10-20 02:40:20
程序有5个文件分别是 :
/*AddMessageServlet.java*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.sql.Connection;
import java.util.*;
import java.io.*;
import java.io.IOException;
public class AddMessageServlet extends HttpServlet
{
private Connection conn;
//接受GET请求,执行数据库操作,把试图派发到下一个页面
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
//接受请求的参数
String name = request.getParameter("name");
String mail = request.getParameter("mail");
String title = request.getParameter("title");
String content = request.getParameter("content");
if(name==null)
name="";
if(mail==null)
mail = "";
if(title==null)
title = "";
if(content==null)
content = "";
try
{
PreparedStatement stm = conn.prepareStatement("insert into message values(?,?,?,?,?)");
stm.setString(1,title);
stm.setString(2,name);
if(mail.length()==0)
stm.setString(5,null);
else
stm.setString(5,mail);
stm.setDate(3,new java.sql.Date(new java.util.Date().getTime()));
stm.setString(4,content);
try
{
stm.executeQuery();

}catch(Exception e)
{
e.printStackTrace();
}
//把 试图派发到目标
RequestDispatcher requestDispatcher = request.getRequestDispatcher("ViewMessageServlet");
requestDispatcher.forward(request,response);


}catch(Exception e)
{
e.printStackTrace();

}

}
//doPost 请求处理
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
doGet(request,response);
}
//创建数据库连接
public AddMessageServlet()
{
String classname = "sun.jdbc.odbc.JdbcOdbcDriver";
String strdb = "jdbc:odbc:message";
String name = "xiaoshitou";
String pwd = "80248024";
try
{
Class.forName(classname);
conn = DriverManager.getConnection(strdb,name,pwd);
//System.out.println("注册成功");


}catch(Exception e)
{
e.printStackTrace();
}
}
}
————————————————————————————————————————————————
/*ViewMessageServlet.java*/
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import java.io.*;
import javax.servlet.ServletRequest;
public class ViewMessageServlet extends HttpServlet
{
private Connection conn;
//接受Get的请求。执行数据库操作,保存到request中,
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
Collection ret =new ArrayList();
try
{
Statement stm = conn.createStatement();
ResultSet result = stm.executeQuery("select count(*)from message");
int message_count = 0;
if(result.next())
{
message_count = result.getInt(1);
result.close();
}
if(message_count>0)
{
result = stm.executeQuery("select * from message order by time desc");
while(result.next())
{
String title = result.getString("title");
String name = result.getString("name");
String mail = result.getString("mail");
String content = result.getString("content");
java.sql.Date Date = result.getDate("time");
MessageVO message = new MessageVO();
message.setName(name);
message.setTitle(title);
message.setContent(content);
message.setDate(Date);
message.setEmail(mail);
ret.add(message);

}
result.close();
stm.close();

}
//保存执行结果,把试图派发到目标
request.setAttribute("message",ret);
//RequestDisPatcher requestDisPatcher = request.getRequestDispatcher("/jsp_servlet_javabean/viewMessage.jsp");
// requestDisPatcher.forward(request,response);
getServletConfig().getServletContext().getRequestDispatcher("/jsp_servlet_javabean/viewMessage.jsp").forward(request,response);

}catch(Exception e)
{
e.printStackTrace();
}


}
//初始化到数据库的连接
public ViewMessageServlet()
{
String classname = "sun.jdbc.odbc.JdbcOdbcDriver";
String strdb = "jdbc:odbc:message";
String name = "xiaoshitou";
String pwd = "80248024";
try
{
Class.forName(classname);
conn = DriverManager.getConnection(strdb,name,pwd);


}catch(Exception e)
{
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
doGet(request,response);
}
}
————————————————————————————————————————————
...全文
26 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
shangyongjun 2004-10-20
谁能帮我测试 一下
回复
shangyongjun 2004-10-20
<!-- index.html -->
<HTML>
<HEAD>
<TITLE> message board </TITLE>
</HEAD>
<LINK href="..\..\hellking.css" type=text/css rel=stylesheet>
<BODY>
<TABLE width="90%" align="center" border=1 cellspacing="0" cellpadding="0" bordercolordark="#CCCC99" bordercolorlight="#CCCC99">
<TR>
<TD align="center" bgcolor="#CCCC99">访客留言板</TD>
</TR>
<TR>
<TD><TABLE align="center" border=1 cellspacing="0" cellpadding="0" bordercolordark="#CCCC99" bordercolorlight="#CCCC99">
<FORM ACTION="/servlet/AddMessageServlet">
<TR>
<TD>姓名:</TD>
<TD bgcolor="#CCCC99"><input type="text" name="name" size=25></TD>
</TR>
<TR>
<TD bgcolor="#CCCC99">E-mail:</TD>
<TD bgcolor="#CCCC99"><input type="text" name="email" size=25></TD>
</TR>
<TR>
<TD>主题:</TD>
<TD bgcolor="#CCCC99"><input type="text" name="title" size=25></TD>
</TR>
<TR>
<TD valign="top" bgcolor="#CCCC99">留言:</TD>
<TD><textarea name="content" rows=7 cols=25></textarea></TD>
</TR>
<TR>
<TD colspan=3><TABLE align="center" width="100%" cellspacing="0" cellpadding="0" bordercolordark="#CCCC99" bordercolorlight="#CCCC99">
<TR>
<TD align="center" bgcolor="#CCCC99"><input type="submit" value="提交留言"></TD>
<TD align="center"><a href="/servlet/ViewMessageServlet"><font size=2>查看留言</font></a></TD>
<TD align="center" bgcolor="#CCCC99"><input type="reset" value="重新填写"></TD>
</TR>
</TABLE></TD>
回复
shangyongjun 2004-10-20
/*MessageVO*/
public class MessageVO implements java.io.Serializable
{
private String name,email,title,content;
private java.sql.Date date;
public MessageVO(){}
public void setName(String name)
{
this.name=name;
}
public void setEmail(String email)
{
this.email=email;
}
public void setTitle(String title)
{
this.title=title;
}
public void setContent(String content)
{
this.content=content;
}
public String getName()
{
return this.name;
}

public String getContent()
{
return this.content;
}
public String getTitle()
{
return this.title;
}
public String getEmail()
{
return this.email;
}
public java.sql.Date getDate()
{
return this.date;
}
public void setDate(java.sql.Date date)
{
this.date=date;
}
}
______________________
错误 是:
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]没有执行可选特性
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLBindInParameterDate(JdbcOdbc.java:809)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setDate(JdbcOdbcPreparedState
ment.java:824)
at AddMessageServlet.doGet(AddMessageServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterC
hain.java:113)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.ja
va:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain
.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocatio
n.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263
)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
at java.lang.Thread.run(Thread.java:534)
java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]没有执行可选特性
at sun.jdbc.odbc.JdbcOdbc.createSQLException(JdbcOdbc.java:6958)
at sun.jdbc.odbc.JdbcOdbc.standardError(JdbcOdbc.java:7115)
at sun.jdbc.odbc.JdbcOdbc.SQLBindInParameterDate(JdbcOdbc.java:809)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setDate(JdbcOdbcPreparedState
ment.java:824)
at AddMessageServlet.doGet(AddMessageServlet.java:37)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:126)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:103)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterC
hain.java:113)
at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.ja
va:211)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain
.java:177)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocatio
n.java:221)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:263
)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:331)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:464)
at com.caucho.util.ThreadPool.run(ThreadPool.java:408)
at java.lang.Thread.run(Thread.java:534)


回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告