dhhjj 2014-04-11 02:10
浏览 6309

基于MyEclipse的登录界面的设计

在MyEclipse下创建servlet,代码如下:
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:1512:XE";
      try
      {
       Class.forName("oracle.jdbc.driver.oracleDriver");
       Connection connection=DriverManager.getConnection(url);
       Statement statement = connection.createStatement();
       String sql="SELECT * FROM +lib_user";
       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
}

}
创建login.jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>

function login_click() { form1.action="Login"; form1.submit(); }
Account:
Password:



配置web.xml:
<?xml version="1.0" encoding="UTF-8"?>

LibraryService


A Login Servlet
LoginServlet
LoginServlet
servlets.LoginServlet


LoginServlet
/LoginServlet


login.jsp


在浏览器输入:http://localhost:8088/LibraryService/login.jsp能显示登录界面,但是输入账号和密码后显示如下:
HTtype Status report

message /LibraryService/Login

description The requested resource is not available.

Apache Tomcat/7.0.53TP Status 404 - /LibraryService/Login
求高手指教,本人刚接触这类软件,实在是找不出问题来,求指教~~~~~~~~~~~~

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题