servlet端调试出错.error message:
Ctx(/WebApp) : Status code:405 request:R( /WebApp + /employeeservlet + null) msg:HTTP method GET is not supported by this URL/*servlet端*/
package com.zcsoft.EmployeeServlet;import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import serializable.EmployeeData;
import java.sql.ResultSet;public class EmployeeServlet extends HttpServlet
{
  //Initialize global variables
  public void init() throws ServletException
  {
  }
  //Process the HTTP Get request
  public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
  {
    DBManager dbBean=new DBManager();
    EmployeeData employee=new EmployeeData();
    ObjectInputStream in=new ObjectInputStream(request.getInputStream());
    try
    {
      employee=(EmployeeData)in.readObject();
      if(employee.getAction()=="Select")
      {
java.sql.ResultSet rs;
java.util.Vector data=null;
rs=dbBean.excuteQuery("select * from basic");
try
{
  while(rs.next())
  {
    data.add(rs.getString(1));
    data.add(rs.getString(2));
    data.add(rs.getString(3));
    data.add(rs.getString(4));
    data.add(rs.getString(5));
    data.add(rs.getString(6));
    data.add(rs.getString(7));
    data.add(rs.getString(8));
  }
}
      catch(java.sql.SQLException exe)
      {
System.out.println("sql exception!");
in.close();
      }
      finally
      {
in.close();
      }
    }
      if(employee.getAction()=="Update")
{
  employee.setRowChanged(dbBean.excuteUpdate("update basic set name='"+employee.getName()+"',birth='"+employee.getBirth()+"',gender="+employee.getBirth()+",edu="+employee.getEdu()+"tel='"+employee.getTel()+"',email='"+employee.getEmail()+"',address='"+employee.getAddress()+"' "+"where num="+employee.getNum()));
  in.close();
}
      if(employee.getAction()=="Delete")
{
   employee.setRowChanged(dbBean.excuteUpdate("delete from basic where num="+employee.getNum()));
   in.close();
}
      if(employee.getAction()=="Add")
{
  employee.setRowChanged(dbBean.excuteUpdate("insert into basic(name,birth,gender,edu,tel,email,address) values('"+employee.getName()+"','"+employee.getBirth()+"',"+employee.getGender()+","+employee.getEdu()+",'"+employee.getTel()+"','"+employee.getEmail()+"','"+employee.getAddress()+"'"));
  in.close();
}
      ObjectOutputStream out=new ObjectOutputStream(response.getOutputStream());
      out.writeObject(employee);
      response.setContentType("application/octest-stream");
      out.flush();
      out.close();
    }
    catch(IOException ex)
    {
      ex.printStackTrace();
    }
    catch(java.lang.ClassNotFoundException exe)
    {
      exe.printStackTrace();
    }
    finally
    {
      //dbBean.dispose();
    }
  }
  //Clean up resources
  public void destroy()
  {
    super.destroy();
  }
}package serializable;public class EmployeeData implements java.io.Serializable
{
  /**/
  private String name=null;
  private String birth=null;
  private boolean gender;
  private int edu;
  private String tel=null;
  private String email=null;
  private String address=null;
  private String action=null;
  private int num;
  private java.util.Vector data=null;
  private boolean rowChange;
  public int getNum()
  {
    return this.num;
  }
  public void setNum(int num)
  {
    this.num=num;
  }
  public String getName()
  {
    return this.name;
  }
  public void setName(String name)
  {
    this.name=name;
  }
   public String getBirth()
  {
    return this.birth;
  }
  public void setBirth(String birth)
  {
    this.birth=birth;
  }
  public String getTel()
  {
    return this.tel;
  }
  public void setTel(String tel)
  {
   this.tel=tel;
  }
  public String getEmail()
  {
    return this.email;
  }
  public void setEmail(String email)
  {
    this.email=email;
  }
  public String getAddress()
  {
    return this.address;
  }
  public void setAddress(String address)
  {
    this.address=address;
  }
  public boolean getGender()
  {
    return this.gender;
  }
  public void setGender(boolean gender)
  {
    this.gender=gender;
  }
  public int getEdu()
  {
    return this.edu;
  }
  public void setEdu(int edu)
  {
    this.edu=edu;
  }
  public String getAction()
  {
    return this.action;
  }
  public void setAction(String action)
  {
    this.action=action;
  }
  public boolean getRowChanged()
  {
   return this.rowChange;
  }
  public void setRowChanged(boolean rowChange)
  {
    this.rowChange=rowChange;
  }
  public java.util.Vector getData()
  {
    return this.data;
  }
  public void setData(java.util.Vector data)
  {
    this.data=data;
  }
}package com.zcsoft.EmployeeServlet;import java.sql.*;
import java.io.*;public class DBManager
{
  public java.sql.ResultSet rs=null;
  public java.sql.Statement stmt=null;
  public java.sql.Connection con=null;
  public java.sql.PreparedStatement presta=null;
  public java.sql.CallableStatement casta=null;
  public String username="sa";
  public String password="test";
  public String driver="sun.jdbc.odbc.JdbcOdbcDriver";
  public String url="Jdbc:Odbc:Employee";
  public DBManager()
  {
    try
    {
      Class.forName(driver);
      con=DriverManager.getConnection(url,username,password);
    }
    catch(Exception e)
    {
      System.err.println("驱动加载错误或用户名密码出错"+e.toString());
    }
  }
  public ResultSet excuteQuery(String sql)
  {
    try
    {
       stmt=con.createStatement();
       return rs=stmt.executeQuery(sql);
    }
    catch(SQLException e)
    {
      e.printStackTrace();
      return null;
    }
    finally
    {
      stmt=null;
    }
  }
  public boolean excuteUpdate(String sql)
  {
    try
    {
      stmt=con.createStatement();
      return stmt.execute(sql);
    }
    catch(SQLException ex)
    {
      ex.printStackTrace();
      return false;
    }
    finally
    {
      stmt=null;
    }
  }
  public void dispose()
  {
    if(con!=null)
      {
if(stmt!=null)
{
  if(rs!=null)
            {
      try
      {
rs.close();
      }
      catch(Exception e)
      {
e.printStackTrace();
rs=null;
      }
    }
    try
    {
      stmt.close();
    }
    catch(Exception e)
    {
      e.printStackTrace();
      stmt=null;
    }
        }      }
      try
      {
con.close();
      }
      catch(Exception e)
      {
e.printStackTrace();
con=null;
      }
    }
}

解决方案 »

  1.   

    Ctx(/WebApp) : Status code:405 request:R( /WebApp + /employeeservlet + null) msg:HTTP method GET is not supported by this URL貌似是说,这个Servlet 不支持 GET. 我看了看你的 Servlet 里面,也没有定义 doGet 方法。你尝试着把public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException修改成public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    看看。
      

  2.   

    干吗把业务逻辑写在service里呢?一般继承HttpServlet只要重写doGet/doPost就好了。
    service方法是用来判断客户请求方式的(GET/POST),他会根据请求方式调用doGet/doPost
      

  3.   

    to:qi37927(),你说的有道理,service的可以处理doGet/doPost的,我的目的是将序列化数据返回
    给brower端.写成多层结构,暂时有点难度.to:Kelvin316,brower是有一处出现URL不正确.brower端代码如下:
    public void actionPerformed(ActionEvent e)
      {
        EmployeeData employee=new EmployeeData();
        java.net.URLConnection con=null;
        try
        {
          if(e.getActionCommand().equals("Update"))
          {
          URL url=new URL("http://localhost:8083/WebApp/server");
          con=url.openConnection();
          con.setDoOutput(true);
          con.setDoInput(true);
          con.setUseCaches(false);
          fillEmployee();
          employee.setAction("Update");
          ObjectOutputStream oos=new ObjectOutputStream(con.getOutputStream());
          oos.writeObject(employee);
          oos.flush();
          oos.close();
          ObjectInputStream ois=new ObjectInputStream(con.getInputStream());
          try
          {
    employee=(EmployeeData)ois.readObject();
    ois.close();
    if(employee.getRowChanged())
    JOptionPane.showConfirmDialog(null,"Update Successfully!","Update Successfully",JOptionPane.OK_OPTION);
    JOptionPane.showConfirmDialog(null,"Update Failed!","Update Failed!",JOptionPane.OK_OPTION);
          }
          catch(java.lang.ClassNotFoundException ex)
          {
    System.out.println("class not found!");
          }
          catch(java.io.IOException exe)
          {
    System.out.println("IO Exception");
          }
          finally
          {
    con=null;
          }
          jtbEmployee.setModel(new TableModel());
          jtbEmployee.updateUI();
        }
        if(e.getActionCommand().equals("Delete"))
        {
          URL url=new URL("http://localhost:8083/WebApp/server");
          con=url.openConnection();
          con.setDoOutput(true);
          con.setDoInput(true);
          con.setUseCaches(false);
          ObjectOutputStream oos=new ObjectOutputStream(con.getOutputStream());
          employee.setNum(num);
          employee.setAction("Delete");
          oos.writeObject(employee);
          oos.flush();
          oos.close();
          ObjectInputStream ois=new ObjectInputStream(con.getInputStream());
          try
          {
    employee=(EmployeeData)ois.readObject();
    ois.close();
    if(employee.getRowChanged())
    JOptionPane.showConfirmDialog(null,"Delete Successfully!","Delete Successfully",JOptionPane.OK_OPTION);
    JOptionPane.showConfirmDialog(null,"Delete Failed!","Delete Failed!",JOptionPane.OK_OPTION);
          }
          catch(java.lang.ClassNotFoundException ex)
          {
    System.out.println("class not found!");
          }
          catch(java.io.IOException exe)
          {
    System.out.println("IO Exception");
          }
          finally
          {
    con=null;
          }
          jtbEmployee.setModel(new TableModel());
          jtbEmployee.updateUI();    }
        if(e.getActionCommand().equals("Add"))
        {
          URL url=new URL("http://localhost:8083/WebApp/server");
          con=url.openConnection();
          con.setDoOutput(true);
          con.setDoInput(true);
          con.setUseCaches(false);
          fillEmployee();
          employee.setAction("Add");
          ObjectOutputStream oos=new ObjectOutputStream(con.getOutputStream());
          oos.writeObject(employee);
          oos.flush();
          oos.close();
          ObjectInputStream ois=new ObjectInputStream(con.getInputStream());
          try
          {
    employee=(EmployeeData)ois.readObject();
    ois.close();
    if(employee.getRowChanged())
    JOptionPane.showConfirmDialog(null,"Add Successfully!","Add Successfully",JOptionPane.OK_OPTION);
    JOptionPane.showConfirmDialog(null,"Add Failed!","Add Failed!",JOptionPane.OK_OPTION);
          }
          catch(java.lang.ClassNotFoundException ex)
          {
    System.out.println("class not found!");
          }
          catch(java.io.IOException exe)
          {
    System.out.println("IO Exception");
          }
          finally
          {
    con=null;
          }
          jtbEmployee.setModel(new TableModel());
          jtbEmployee.updateUI();
        }
        }
        catch(MalformedURLException exe)
        {
          exe.printStackTrace();
        }
        catch(IOException ex)
        {
          ex.printStackTrace();
        }
      }
    update,delete,add.ActionEvent事件出错,出错信息如下:
    java.net.ConnectException: Connection refused: connect
      

  4.   

    DBManager类里面创建Connection的URL貌似不正确,创建Connection本身就已经失败了,去get的话当然会出错了。
    -----------------我是传说中的分割线----------------
    我也是刚刚起步,不知道说的是否正确