日期:2014-05-17  浏览次数:20732 次

为啥的的mvc中得servlet失败,不过编译成功了,再tomcat运行不了
servlet  
loginservlet.java


package test;
import dbcon.DB;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class loginservlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException{
  request.setCharacterEncoding("GBK");
  HttpSession mysession=request.getSession(true);
 if(mysession==null)
  {
  response.sendRedirect("Clogin.jsp");
  }
  try{
  String user=request.getParameter("uid");
  String passward=request.getParameter("password"); 
  DB db=new DB();
  boolean A=db.check(user,passward);
  if(A=true)
  {response.sendRedirect("chenggong.jsp");}
  else{response.sendRedirect("shibai.jsp");}
}catch (Exception e){}
  }

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
 doGet(request,response);
  }



javabean DB.java


package dbcon;
import java.sql.*;

public class DB{

  private Connection conn;
  private Statement stmt;
  private ResultSet rs;

  public void getcon()throws Exception{
 
  Class.forName("com.mysql.jdbc.Driver").newInstance();
  conn= DriverManager.getConnection("jdbc:mysql://localhost/test","root","root");
  stmt=conn.createStatement();
  }
public boolean check(String uid,String passward)throws Exception


String selectquery="select * from student where Name='"+uid+"'";
boolean A=true;
rs=stmt.executeQuery(selectquery);
if(rs.next())
{ A=true;}
else{A=false;};

return A;

}
public void close()throws Exception{

conn.close();
stmt.close();
}

}

jsp  
<%@page language="java" contentType="text/html;charset=GBK"%>
<html>
 <head>
  <title>报名系统 </title>
 </head>
 <table>
  <form name="login" action="loginservlet" method="post">
<tr> 
  <td>登录名:<input type="text" name="uid" ></td>
</tr>
<tr>
  <td>密&&码:<input type="text" name="passward" ></td>
</tr>
<tr>
  <td> <input type="submit" value="登陆" ></td>
  <td> <input type="button" value="注册" onclick="window.location='Cregister.jsp'"></td>
</tr>

</form>

</table>


ps:其他运行都正常就是servlet失败了,失败的提示如下::


------解决方案--------------------
说的很明白,没找到dbcon.DB,看你的容器里的工程目录有这个class没
------解决方案--------------------
String selectquery="select * from student where Name='"+uid+"'";
应该是这句错了。
String selectquery="select * from student where Name="+uid;

------解决方案--------------------
探讨