读书人

为什么的的mvc中得servlet失败不过编

发布时间: 2012-10-18 13:46:56 作者: rapoo

为啥的的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;

[解决办法]

探讨
String selectquery="select * from student where Name='"+uid+"'";
应该是这句错了。
String selectquery="select * from student where Name="+uid;



[解决办法]
看看你的DB类是不是也放到classes/test下边去了.
[解决办法]
eclipse的奇怪问题 你关闭项目 重新部署 就好了 我也碰见类似的
[解决办法]
这问题我也遇到了, 同样求解啊...

读书人网 >Java Web开发

热点推荐