Find Idsql Statement Web interface Connection database

Source: Internet
Author: User
Tags stub

Import java.io.IOException;
Import Java.io.PrintWriter;
Import java.sql.Connection;
Import Java.sql.DriverManager;
Import java.sql.PreparedStatement;
Import Java.sql.ResultSet;
Import java.sql.SQLException;
Import java.util.ArrayList;
Import java.util.List;

Import Javax.servlet.ServletConfig;
Import javax.servlet.ServletException;
Import Javax.servlet.annotation.WebServlet;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;

/**
* Servlet Implementation Class Infoservlet
*/
@WebServlet ("/infoservlet")
public class Infoservlet extends HttpServlet {
Private static final long serialversionuid = 1L;
UserInfo UserInfo = new UserInfo ();
Private Connection Conn;
Private ResultSet RS;
Private PreparedStatement PST = NULL;
/**
* @see Httpservlet#httpservlet ()
*/
Public Infoservlet () {
Super ();
TODO auto-generated Constructor stub
}

/**
* @see Httpservlet#doget (httpservletrequest request, httpservletresponse response)
*/
protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
DoPost (request, response);
}

/**
* @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response)
*/
protected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
Set the character set encoding for response content
Request.setcharacterencoding ("Utf-8");
Get form data
String name = Request.getparameter ("name");
String Password = request.getparameter ("password");
TODO auto-generated Method Stub
Setting the response content type
Response.setcontenttype ("text/html");
Set the character set encoding for response content
Response.setcharacterencoding ("Utf-8");
Get response content output stream
PrintWriter out = Response.getwriter ();
Connecting to a database
try {
Class.forName ("Com.mysql.jdbc.Driver");
conn = Drivermanager.getconnection ("Jdbc:mysql://127.0.0.1:3306/xx", "root", "root");
String str = "SELECT id from the text where name=?" and password =? ";
PST = conn.preparestatement (str);
Pst.setstring (1, name);
Pst.setstring (2, password);
rs = Pst.executequery ();
while (Rs.next ()) {
Userinfo.setid (Rs.getint ("id"));
}

} catch (ClassNotFoundException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
try {
System.out.println (Rs.getint ("id"));
} catch (SQLException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
SYSTEM.OUT.PRINTLN (name);
SYSTEM.OUT.PRINTLN (password);
System.out.println (Userinfo.getid ());
if (Userinfo.getid ()!=0) {
Response.sendredirect ("Http://localhost:8080/Myhome/YesServlet");

}else{
Response.sendredirect ("Http://localhost:8080/Myhome/NoServlet");

}
Out.close ();
}
}

Find Idsql Statement Web interface Connection database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.