日期:2014-05-18  浏览次数:20622 次

问题标签用户 基于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();