基于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后显示登录界面,但是输入账号和密码后跳转页面上什么也没有,不论输入什么账号和密码都不显示登录成功或不成功,求帮助~~~~
...全文
479 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
angleman123 2014-04-25
  • 打赏
  • 举报
回复
doPost()里怎么写的
-江沐风- 2014-04-14
  • 打赏
  • 举报
回复
换5楼的试试吧;
m3621552 2014-04-14
  • 打赏
  • 举报
回复
[quote=引用 楼主 dhhjj 的回复:] //联结字符串 String url="jdbc:oracle:thin:@localhost:1521:"+dbName+"?user="+userName+"&password="+userPasswd; 我记得都是用冒号连接的, 你试试改成冒号呢
dhhjj 2014-04-14
  • 打赏
  • 举报
回复
引用 3 楼 u012724379 的回复:
1.看看你的

       catch(SQLException e)
       {
             System.out.println(e);
       }
里有没有异常出现; 2.看看你的跳转没问题吧;
没有出现异常,请问怎么看跳转有问题呢?
dhhjj 2014-04-14
  • 打赏
  • 举报
回复
引用 5 楼 yangqingwen520 的回复:
连接数据库url地址改改: 我的是这样的:conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORACLE", "wenwen", "wen123"); 你的用户名和密码那里好像有点出入?按照我的方式去试试!
试了一下,但是登录之后还是不能显示登录成功或者登录失败
dhhjj 2014-04-13
  • 打赏
  • 举报
回复
请问楼上应该怎么修改呢?求指教~~
teemai 2014-04-13
  • 打赏
  • 举报
回复
doPost方法没跳转
yangqingwen520 2014-04-13
  • 打赏
  • 举报
回复
连接数据库url地址改改: 我的是这样的:conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:ORACLE", "wenwen", "wen123"); 你的用户名和密码那里好像有点出入?按照我的方式去试试!
-江沐风- 2014-04-13
  • 打赏
  • 举报
回复
1.看看你的

       catch(SQLException e)
       {
             System.out.println(e);
       }
里有没有异常出现; 2.看看你的跳转没问题吧;

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧