?? firstservlet.java
字號(hào):
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class firstservlet extends HttpServlet
{
static Connection con;
static String resulttosecond="NA";
public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:MyDataSource","faculty","");
}
catch(Exception e)
{
System.out.println(e);
}
ServletContext context = getServletContext();
context.setAttribute("accountnumber","");
String accnum = req.getParameter("accnum");
String pinnum = req.getParameter("pinnum");
try{
PreparedStatement s = con.prepareStatement("select * from login where cAccount_Id=? and cPin_no=?");
s.setString(1,accnum);
s.setString(2,pinnum);
ResultSet rs = s.executeQuery();
boolean rowfound = false;
rowfound = rs.next();
if (rowfound == true)
{
resulttosecond = rs.getString(1);
context.setAttribute("accountnumber",resulttosecond);
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/secondservlet");
if (dispatcher == null)
{
res.sendError(res.SC_NO_CONTENT);
}
dispatcher.forward(req,res);
try{
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
if (rowfound == false)
{
PrintWriter out = res.getWriter();
res.setContentType("text/html");
resulttosecond = "NA";
out.println("<html>");
out.println("<body bgcolor=pink>");
out.println("Pls check the values that you have entered");
out.println("</body>");
out.println("</html>");
out.close();
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -