Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

login page for web portal  RSS feed

 
fara purple
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hye everyone..
i'm new to jsp. I have some problems for my login page. I hope that you can help me to solve this problem.
Thank You..

Here is my code:

<%@ page contentType="text/html"
import="java.sql.*, java.util.Date, java.io.*" %>
<%!
String CheckLogin(String Login, String Password) throws Exception
{
Connection con = null;
ResultSet rs = null;
String result = null;
String strSQL = "";



try{

Class.forName( "org.postgresql.Driver" );
con = DriverManager.getConnection("jdbc:postgresql://localhost:5432/web_portal","postgres","williamlcs");

strSQL = "SELECT * FROM all_user WHERE user_login=?";
PreparedStatement ps = con.prepareStatement(strSQL);
ps.setString(1,Login);
rs = ps.executeQuery();
if(!rs.next())
result = "Invalid Account";
else if(!rs.getString("user_pwd").equals(Password))
result = "Invalid Password";
else
result = "loginSucc";

ps.close();
}
catch(Exception ex){
throw ex;
}
finally{
rs.close();
con.close();
}

return result;
}
%>
<%
String UserNm = request.getParameter("UserNm");
String UserPasswd = request.getParameter("UserPasswd");

if(UserNm == null || UserPasswd == null){
response.sendRedirect("homepage.html");
}

String strCheckLogin = CheckLogin(UserNm, UserPasswd);

if(strCheckLogin.equals("loginSucc")){
session.setAttribute("UserNm", UserNm);
session.setAttribute("UserPasswd", UserPasswd);
response.sendRedirect("IT.html");

}
%>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Login</TITLE>
</HEAD>



<CENTER>
<%= strCheckLogin %>



</CENTER>
</BODY>
</HTML>
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that if you're just starting out, this is a perfect opportunity to understand why Java code should go in a servlet, and not in a JSP--might as well start off on the right foot!
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And one more tip to you is, use jstl and el instead of scriptlets.

Keep going :thumbup:
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I said.
 
chaitanya karthikk
Ranch Hand
Posts: 806
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I dint mean it in that way.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!