NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Problem with jsp:forward

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
madafak14



Joined: 10 Sep 2009
Posts: 5

PostPosted: Mon Sep 14, 2009 4:15 pm    Post subject: Problem with jsp:forward Reply with quote

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<sql:query var="userPassRs" dataSource="jdbc/RETROSPEKTIVA">
SELECT * FROM Korisnik
WHERE KorisnickoIme = '<%= request.getParameter("KorisnickoIme") %>'
AND Lozinka = '<%= request.getParameter("Lozinka") %>'
</sql:query>
<c:set var="userPass" scope="request" value="${userPassRs.rows[0]}"/>

<jsp:useBean id="validUser" scope="session" class="retrospektiva.Korisnik"/>
<jsp:setProperty name="validUser" property="username" value="${userPass.KorisnickoIme}" />
<jsp:setProperty name="validUser" property="password" value="${userPass.Lozinka}" />
<jsp:setProperty name="validUser" property="name" value="${userPass.ImeKorisnika}" />
<jsp:setProperty name="validUser" property="lastName" value="${userPass.PrezimeKorisnika}" />
<jsp:setProperty name="validUser" property="userType" value="${userPass.TipKorisnika}" />
<html>
<head><title>idemo</title></head>
<body>
<%
String usrtype = validUser.getUserType();

if (usrtype == "admin")
{
%>
<jsp:forward page = "jsp/administrator.jsp"/>
<%
}
else if (usrtype == "prof")
{
%>
<jsp:forward page = "profesor.jsp"/>
<%
}
else if (usrtype == "stud")
{
%>
<jsp:forward page = "student.jsp"/>
<%
}
else
{
out.println("Login failed");
}
%>
</body>
</html>


Here is the code for my authenticate.jsp page. I keep getting "Login failed" message. Does anyone know where the mistake is?
Back to top
Bman



Joined: 16 Sep 2009
Posts: 1

PostPosted: Wed Sep 16, 2009 10:50 pm    Post subject: Reply with quote

Change the way you compare strings in these 3 lines:
Code:
if (usrtype == "admin")

else if (usrtype == "prof")

else if (usrtype == "stud")

using the compareTo() method which returns 0 when string objects are equal, so it looks like:

Code:
if (usrtype.compareTo("admin") == 0)

else if (usrtype.compareTo("prof") == 0)

else if (usrtype.compareTo("stud") == 0)
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo