第一次写Servlet调得都快崩溃了 哪位大哥帮我看下 万分感激~!
Tomcat报异常
java.io.DataInputStream.readUnsignedShort(DataInputStream.java:310)
java.io.DataInputStream.readUTF(DataInputStream.java:545)
java.io.DataInputStream.readUTF(DataInputStream.java:522)
MyServlet.PlaceServlet.doGet(PlaceServlet.java:51)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
代码是这样的:
(数据库是我用ACCESS建了一个表,里面4个列名。Place Time Introduction TicketPrice 我主要是想从手机客户端连接服务器,调试这个SERVLET的时候就是调不成功,不知道哪里错了!哪位大哥知道帮我看一下愿意帮忙的留个QQ我发客户端代码帮我调下 谢谢了!
import java.io.*;
import java.net.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class PlaceServlet extends HttpServlet {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
DataOutputStream dos = null;
boolean FOne = false;
String CNFirst = "对不起!没有记录!";
boolean flag = false;
String returnMessage = "";
String Place = "";
String Time = "";
String Introduction = "";
String TicketPrice="";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
//设置响应属性
response.setContentType("text/html;charset=GBK");
//接收客户请求
InputStream is = request.getInputStream();
DataInputStream dis = new DataInputStream(is);
//读取景点信息
String Place = dis.readUTF();
try{
//注册数据库
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){}
try {
conn = DriverManager.getConnection("jdbc:odbc:travelplace");
stmt = conn.createStatement();
rs = stmt.executeQuery("Select * from travelPlace where Place="+"'"+Place+"'");
while(rs.next()){
Place = rs.getString("Place");
Time = rs.getString("Time");
Introduction = rs.getString("Introduction");
TicketPrice = rs.getString("TicketPrice");
FOne = true;
}
String returnMessage = "景点:"+Place+"开放时间:"+Time+"景点介绍:"+Introduction+"票价:"+TicketPrice;
//发送处理后的信息给手机
dos = new DataOutputStream(response.getOutputStream());
dos.writeUTF(returnMessage);
}
catch(SQLException e){
throw new ServletException(e.getMessage());
}
catch(Exception e1){
throw new ServletException(e1.getMessage());
}finally{
if(dis!=null){
try{
dis.close();
}catch(IOException e){
throw new ServletException("dis close failed");
}
}
if(dos!=null){
try{
dos.close();
}
catch(IOException e)
{
throw new ServletException("dos close failed");
}
}
if(conn != null){
try{
conn.close();
}catch(SQLException e){
throw new ServletException("connection clsoe failed");
}
}
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{
doGet(request,response);// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
}
//清除资源
public void destroy(){
}
}