/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Administrator
*/
public class login extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, ClassNotFoundException, SQLException {
response.setContentType("text/html;charset=UTF-8");
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet 方法。单击左侧的 + 号以编辑代码。">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (ClassNotFoundException ex) {
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
processRequest(request, response);
} catch (ClassNotFoundException ex) {
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
}
//response.setCharacterEncoding("UTF-8");
//byte[] b = request.getParameter("name").getBytes("ISO-8859-1");
//String t = new String(b,"GB2312");
String account = new String(request.getParameter("name").getBytes("iso-8859-1"),"GB2312");
String pin = new String(request.getParameter("PIN").getBytes("iso-8859-1"),"GB2312");
if (account.equals("guest") && pin.equals("*")) {
AnnoySet(request, response, "guest");
return;
}
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:OK");
java.sql.Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String select = "Where Account='";
select += account + "' and Pin='";
select += pin + "'";
select = "select * from user " + select;
ResultSet rs = stmt.executeQuery(select); //建立ResultSet(结果集)对象,并执行SQL语句
if (!rs.next()) {
response.sendRedirect("index.jsp?errormsg=" + account);
return;
} else {
Set(request, response, account);
}
rs.close();
stmt.close();
con.close();
} catch (SQLException ex) {
response.sendRedirect("index.jsp?errormsg=" + account);
} catch (ClassNotFoundException ex) {
response.sendRedirect("index.jsp?errormsg=" + account);
}
}
private void Set(HttpServletRequest request, HttpServletResponse response, String account) {
PrintWriter out = null;
try {
response.setContentType("text/html;charset=GBK");
out = response.getWriter();
String name = new String(request.getParameter("name").getBytes("iso-8859-1"),"GB2312");
String html = "<html><body BGCOLOR='#889988' TEXT='#778899'> <center> " +
"<marquee behavior=slide direction=up><img src=topbg.jpg></marquee></center>" +
"<hr><marquee behavior=scroll direction=up height=8%><center><font size=7 color=668866 >Welcome ";
html += name + " to Our BBS Forum</font></marquee></center></marquee>";
html += "<marquee behavior=scroll direction=down height=8%><center><font size=7 color=668866 >Welcome ";
html += name + " to Our BBS Forum</font></marquee></center></marquee>";
out.println(html);
html = "<hr><br><br> <table width=100% border=0 cellspacing=0 cellpadding=0><tr>" +
"<td align=left><a href=EductTip.jsp?id=" + account + "|><font size=7 color=#006600/><b/>Education Area</td>" +
" <td align=center><a href=SportTip.jsp?id=" + account + "|><font size=7 color=#006600/><b/>Sport Zone</td>" +
" <td align=right><a href=RelaxTip.jsp?id=" + account + "|><font size=7 color=#006600/><b/>Leisure Region</td>" +
" </tr>" +
"</table>";
out.println(html);
html = "<hr><table width=100% border=0 cellspacing=0 cellpadding=0><tr color=#889988>" +
"<td ><marquee direction=right><a href=EductTip.jsp?id=" + account + "|><img src=Edu.jpg></marquee></td>" +
"<td ><marquee direction=left><a href=EductTip.jsp?id=" + account + "|><img src=Edu.jpg></marquee></td>" +
" <td ><marquee direction=right><a href=SportTip.jsp?id=" + account + "|><img src=Sport.jpg></marquee></td>" +
" <td ><marquee direction=left><a href=SportTip.jsp?id=" + account + "|><img src=Sport.jpg></marquee></td>" +
" <td ><marquee direction=right><a href=RelaxTip.jsp?id=" + account + "|><img src=Leisure.jpg></marquee></td>" +
" <td ><marquee direction=left><a href=RelaxTip.jsp?id=" + account + "|><img src=Leisure.jpg></marquee></td>" +
" </tr>" +
"</table>";
out.println(html);
html = "</body></html>";
out.println(html);
out.close();
} catch (IOException ex) {
Logger.getLogger(login.class.getName()).log(Level.SEVERE, null, ex);
} finally {
out.close();
}
}
private void AnnoySet(HttpServletRequest request, HttpServletResponse response, String guest) {
PrintWriter out = null;
try {
response.setContentType("text/html");
out = response.getWriter();
String html = "<html><body BGCOLOR='#889988' TEXT='#778899'> <center> " +
"<marquee behavior=slide direction=up><img src=topbg.jpg></marquee></center>" +
"<hr>" +
"<table width=100% border=0 cellspacing=0 cellpadding=0 >" +
"<tr><th><marquee direction=left height=8%><font size=7 color=668866 >muroF ";
html += "SBB ruO ot emocleW</font></marquee></marquee></th>";
html += "<th><marquee direction=right height=8%><font size=7 color=668866 >Welcome ";
html += "to Our BBS Forum</font></marquee></marquee></th></tr></table>";
out.println(html);
html = "<hr><br><br> <table width=100% border=0 cellspacing=0 cellpadding=0><tr>" +
"<td align=left><a href=