基于MyEclipse+tomcat+Oracle设计的登录页面问题,求助~~~~~~
dhhjj 2014-04-13 09:15:26 在MyEclipse中创建的LoginServlet如下:
package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
public class LoginServlet extends HttpServlet {
private String name;
private String pass;
/**
* Constructor of the object.
*/
public LoginServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.name=request.getParameter("account");
this.pass=request.getParameter("password");
PrintWriter out=response.getWriter();
//驱动程序名
String driverName="oracle.jdbc.driver.oracleDriver";
//数据库用户名
String userName="system";
//密码
String userPasswd="zmh";
//数据库名
String dbName="XE";
//表名
String tableName="lib_user";
//联结字符串
String url="jdbc:oracle:thin:@localhost:1521:"+dbName+"?user="+userName+"&password="+userPasswd;
try
{
Class.forName("oracle.jdbc.driver.oracleDriver");
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="SELECT * FROM "+tableName;
ResultSet rs = statement.executeQuery(sql);
while(true)
{
if(rs.next())
{
if((this.name.equals(rs.getString(1)))&&(this.pass.equals(rs.getString(2))))
{
out.print("<h1>"+"Login Success!");
break;
}
}
else
{
out.print("<h1>"+"Account or Password Is Invalid!");
break;
}
}
return;
}
catch(SQLException e)
{
}
catch(ClassNotFoundException e)
{
}
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
Oracle数据库已经连接,在网页中输入http://localhost:8088/LibraryService/index.jsp后显示登录界面,但是输入账号和密码后跳转页面上什么也没有,不论输入什么账号和密码都不显示登录成功或不成功,求帮助~~~~