简单的登录servlet不提供输出

时间:2017-10-01 13:32:44

标签: java servlets jdbc

我开发了简单的登录servlet,它在eclipes中运行良好,但我没有从服务器端获得任何输出帮助修复此问题 使用了create statement not prepared statement 有助于改善逻辑

  

的index.html   

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>welcome to Student Account</title>
</head>
<body>
	<font color="red">
		<center>
			Welcome to Student portal <br> <b>kindly login to your acccount</b></br> <b>Login
				form</b>
			<form method="post" action="./Account">
				<table>
					<tr>
						<td>Student Login:</td>
						<td><input type="text" name="sname"></td>
					</tr>
					<tr>
						<td>Student Password:
						<td><input type="password" name="spasswd"></td>
					</tr>
					<tr>
						<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						<td><input type="submit" value="login">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
							type="reset" value="reset"></td>
					</tr>
				</table>
		</center>
</body>
</html>

     
    

StudentAccInfo.java

  
   import java.io.IOException;
   import java.io.PrintWriter;

   import javax.servlet.ServletException;
   import javax.servlet.annotation.WebServlet;
   import javax.servlet.http.HttpServlet;
   import javax.servlet.http.HttpServletRequest;
   import javax.servlet.http.HttpServletResponse;

   @WebServlet("/Account")
   public class StudentAccInfo extends HttpServlet {
   private static final long serialVersionUID = 1L;

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    String sname=request.getParameter("sname");
    String spasswd=request.getParameter("spasswd");
    String Status=UserService.validate(sname, spasswd);
    out.println("<html><body><center>");
    out.println("<font color='red' size='7'>");
    if(Status.equals("success")){
        out.println("Login Success");
    }
    if(Status.equals("failure")){
        out.println("Login failure");
    }
    out.println("</center></body></html>");     

}

}

  
    

UserService.java

  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;

 public class UserService {

public  static String validate(String sname, String spasswd)
{
    Connection con=null;
    Statement st=null;
    ResultSet rs=null;
    String Status="";
try{
    Class.forName("oracle.jdbc.OracleDriver");
    con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "tiger");
    st=con.createStatement();
    String sql="";
      sql=sql+"select * from std where sname=";
      sql=sql+"'"+sname+"'";
      sql=sql+" "+"and spasswd=";
      sql=sql+"'"+spasswd+"'";

      rs=st.executeQuery(sql);
      boolean b=rs.next();
      if(b==true){
          Status="success";
      }else{
          Status="failure";
      }
       }catch(Exception e){
          e.printStackTrace();
      }finally {
          try{
                 con.close();
                 st.close();
                 rs.close();
             }catch(Exception e){
                e.printStackTrace(); 
             }
            }
return Status;
}
}

注意: - 我使用了create Statement not prepared statement

运行良好但没有获得输出

1 个答案:

答案 0 :(得分:1)

从操作属性

中删除 ./
<form method="post" action="Account">