I have written a jsp login function which allowed two differnet user to enter different username and password in order to enter the other page. After the user entered the correct username and password, i dont know how to put a link in jsp to let each user link to a different web page, can anyone help???
<%@ page import="java.util.*"%>
<html>
<head><title>Login</title></head>
<body>
<%!
protected Map users= new HashMap();
public void jspInit(){
//username and password
users.put("fiona", "happy"
;
users.put("henry", "leader"
;
}
%>
<%
String username = request.getParameter("username"
;
String password = request.getParameter("password"
;
if (username != null)
username= username.trim();
if(password != null)
password= password.trim();
if (username != null && username.length() >0) {
if (password != null && password.length() >0) {
String pw = (String) users.get(username);
if (pw != null){
if(pw.equals (password)){
String firstname = username;
int i = username.indexOf (' ');
if (i>0)
firstname = username.substring (0, i);
%>
<h1> Login sucessful. </h1>
<%
} else { %>
<h1> Loginfail. Sorry, incorrect password.</h1>
<%
}
} else { %>
<h1>Login fail. Sorry, not a user. </h1>
<%
}
} else { %>
<h1> Loginin fail. Sorry, no password. </h1>
<%
}
} else { %>
<h1> Login fail. Sorry, no username. </h1>
<%
}
%>
</body>
</html>
<%@ page import="java.util.*"%>
<html>
<head><title>Login</title></head>
<body>
<%!
protected Map users= new HashMap();
public void jspInit(){
//username and password
users.put("fiona", "happy"
users.put("henry", "leader"
}
%>
<%
String username = request.getParameter("username"
String password = request.getParameter("password"
if (username != null)
username= username.trim();
if(password != null)
password= password.trim();
if (username != null && username.length() >0) {
if (password != null && password.length() >0) {
String pw = (String) users.get(username);
if (pw != null){
if(pw.equals (password)){
String firstname = username;
int i = username.indexOf (' ');
if (i>0)
firstname = username.substring (0, i);
%>
<h1> Login sucessful. </h1>
<%
} else { %>
<h1> Loginfail. Sorry, incorrect password.</h1>
<%
}
} else { %>
<h1>Login fail. Sorry, not a user. </h1>
<%
}
} else { %>
<h1> Loginin fail. Sorry, no password. </h1>
<%
}
} else { %>
<h1> Login fail. Sorry, no username. </h1>
<%
}
%>
</body>
</html>