在登录页面填写好用户名密码后,点击提交这时候,MyEclipse就会被调出来说是要debug,然后就提示
=》request.setCharacterEncoding("gb2312");这句话有问题,提示:Multiple er at this line
-Line breakpoint :Login[line:32]-doGet(HttpServletRequest,HttpServletResponse)
-Debug Current Instruction Pointer
不知这是什么原因啊?如果我把request.setCharacterEncoding("gb2312");注释掉,有提示下一句
HttpSession mySession = request.getSession(true);有问题。
* This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/).
*/
import java.io.*;
//import java.util.Hashtable;
import java.sql.*;import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;//import ch04.*;/**
* 针对登录页面的Servlet
* @author ShenYK
* @version 1.0
*/
public class Login extends Common
{
public void doGet ( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
//设置提交表单的中文编码
// request.setCharacterEncoding("gb2312");
HttpSession mySession = request.getSession(true);
//清空错误消息
mySession.setAttribute("errMsg","");
//是否进入默认页面
if ( !request.getParameterNames().hasMoreElements() )
{
response.sendRedirect("../index.jsp");
return;
}
//得到用户输入信息
String sUsername = request.getParameter("username");
String sPassword = request.getParameter("password");
//String sRole = request.getParameter("role"); //如果用户是提交表单
if ( sUsername != null && sUsername.length() > 0 )
{
//校验用户输入信息
String sRealname = getUserRealname( sUsername, sPassword);
if ( sRealname == null )
{
//出错了设置变量并重新显示
mySession.setAttribute( "errMsg", "登录失败!请重新输入相关信息!" );
mySession.setAttribute( "username", sUsername );
//mySession.setAttribute( "role", sRole );
response.sendRedirect("../failure.jsp");
return;
}
else
{
mySession.setAttribute( "username", sUsername );
mySession.setAttribute( "realname", sRealname );
//根据用户角色的不同决定迁移到哪个页面
/* if ( sRole.equals( "0" ) )
{
//学生角色则迁移到选课一览页面
response.sendRedirect( "../servlet/ChooseCourse" );
}
else
{
//教师角色则迁移到选课结果一览页面
response.sendRedirect( "../servlet/CourseList" );
}*/
response.sendRedirect( "../WebRoot/success.jsp" );
return;
}
}
//如果用户非法进入这个页面
else
{
response.sendRedirect("../index.jsp");
return;
}
}
public void doPost ( HttpServletRequest request,
HttpServletResponse response )
throws ServletException, IOException
{
doGet( request, response );
}
private String getUserRealname(String sUsername, String sPassword)
{
//获得数据库连接
Connection conn = this.getDBConnection();
if ( conn == null )
{
return null;
}
Statement stmt = null;
ResultSet rs = null;
try
{
stmt = conn.createStatement();
//执行SQL语句
String sQuery = "select * from admin where name='" + sUsername + "' "
+ "and password='" + sPassword +"'";
rs = stmt.executeQuery( sQuery );
String sRealname = null;
if ( rs.next() )
{
sRealname = rs.getString( "realname" );
}
return sRealname;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
finally
{
try
{
rs.close();
stmt.close();
conn.close();
}catch(Exception ex)
{
}
}
}
}
以下是登录信息填写页面:<%@ page contentType="text/html;charset=gbk" language="java"
import="java.util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
body {
background: url(img/stray.jpg);
background-position: center;
background-repeat: no-repeat;
}
</style> </head> <body>
<h2 align="center">
Book Management System
</h2>
<br />
<br />
<form action="servlet/Login" method="post">
<table align="center"> <tr>
<td>
Username:
</td>
<td>
<input type="text" size="19" name="username" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="password" size="20" name="password" />
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="submit" />
</td>
<td align="center">
<input type="reset" value="reset " />
</td>
</tr>
</table>
</form>
</body>
</html>
public class Login extends Common
{
这个common是什么类啊?
package servlet;/*
* This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/).
*/import java.sql.*;import javax.servlet.http.*;/**
* 针对一些共通处理的父类
* @author ShenYK
* @version 1.0
*/
public class Common extends HttpServlet
{
public Connection getDBConnection()
{
//尝试连接数据库
try
{
//载入MySQL的JDBC驱动类
Class.forName( "com.mysql.jdbc.Driver" );
//获得数据库连接
Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost/book?user=root&password=891014" );
return conn;
}
catch(Exception ex)
{
ex.printStackTrace();
return null;
}
}
}
这样设置之后,以后服务器就是在run mode下运行了
但是我还是想问问tomcat启动方式中debug mode与run mode有什么区别吗?
debug就是让你用来调试程序的
run模式是直接全部编译一边 除非程序有问题 不然不会停