wood burning stoves 2.0*
The moose likes JSP and the fly likes Error while forwarding page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Error while forwarding page" Watch "Error while forwarding page" New topic
Author

Error while forwarding page

Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi;
The below page validates the user. if the groupid of the user is null into the database,it forward the user to accessdenied.jsp page.
It works fine for valid user but not working for unauthorised user .i.e fails to forward the page accessdenied.jsp



2. Can i access the variable groupid in try.jsp page by request.getparameter() method.
If not then can any have the alternative way for accessing same variable in try.jsp page.
Thanks and Regards
Harshal
[ July 28, 2008: Message edited by: Harshal Gurav ]
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Kindly help me.
Matteo Di Furia
Ranch Hand

Joined: Jun 20, 2008
Posts: 102
Provide us with some error message (if you got any ?!).
What happens when the user is unauthorized ? What get visualized in the result page ?
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi;
Thanks for your suggestion.
As i am trying to test with database field it gives me right result for username and password field. but when i tried it with arbitrally name it shows the same page without forwarding it to abc.jsp page
Here is my result page:


thanks in advance
Regards
Harshal
mohanasundaram muthukannan
Ranch Hand

Joined: May 29, 2008
Posts: 35
Hi Harshal ,

you didn't close Connection object.

finally {
if (rs != null) {
rs.close();
rs=null
}
if (stmt != null)
{
stmt.close();
stmt = null;
}
if (conn != null)
{
conn.close();
conn = null;
}


You should close you're Connection object.

Regards,
yemyemyes
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"yemyemyes m",
Please check your private messages regarding an important administrative matter.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi,
Thanks for your suggestion.
with closing connection,my jsp page is not working . It unable to direct to the accessdenied page for unauthorized user.

Thanks and Regards
Harshal
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

You should close you're Connection object.


But I dont think that will stop the forward


SCJP, SCWCD.
|Asking Good Questions|
mohanasundaram muthukannan
Ranch Hand

Joined: May 29, 2008
Posts: 35
Hi,

Please try this source code


<%-- Document : as Created on :
Jul 26, 2008, 12:41:17 PM
Author : user1--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java"%>
<%@ page
import="java.sql.*,javax.sql.*,javax.naming.*,java.io.*,java.util.*"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String userid = request.getParameter("userid");
String password = request.getParameter("password");
InitialContext context = new InitialContext();
DataSource ds = (DataSource) context
.lookup("java:comp/env/jdbc/mynewdatabase");
Connection conn = ds.getConnection();
context.close();
ResultSet rs = null;
Statement stmt = null;
String groupId=null;
stmt = conn.createStatement();
try {
rs = stmt
.executeQuery("select groupid from user where emailid='"
+ userid + "' and Password='" + password + "'");
%>
<%

while (rs.next()) {
%>
<%
groupId = rs.getString("username");
out.println(groupId);
out.println("Invalid User");
}
} catch (Exception e) {

} finally {
if (stmt != null) {
stmt.close();
}

if (rs != null) {
rs.close();
}
if (conn != null)
conn.close();
}

if (groupId == null) {
%>
<jsp:forward page="/abc.jsp" />
<%
} else {
out.println("Valid User");
%>
<jsp:forward page="/try.jsp" />
<%
}
%>
</body>
</html>


Regards,
mohanasundaram
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

Hi mohanasundaram muthukannan
please UseCodeTags.
You can add code tags by clicking the button.
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi mohanasundaram;
Thanks for your reply.
You suggested code is working nice.
In your code , you closed resultset and statement object before the page forwarded. Due to this I unable to transmit parameter like:

to the another page.
And with updating it , can not transmit it to abc.jsp for valid user.
Here is an updated one:


Thanks and Regards
Harshal

[ July 28, 2008: Message edited by: Harshal Gurav ]

[ July 28, 2008: Message edited by: Harshal Gurav ]

[ July 28, 2008: Message edited by: Harshal Gurav ]
[ July 28, 2008: Message edited by: Harshal Gurav ]
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
what is wrong with above code?
regards
Harshal
mohanasundaram muthukannan
Ranch Hand

Joined: May 29, 2008
Posts: 35
Hi Harshal Gurav ,


try this code



and for what you use again Resultset?
just you store one variable and send another page

Regards,
Mohanasundaram
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi,
Thanks for your post.
and Yes, i can use variable by closing the resultset first.
Thanks again
regards
harshal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error while forwarding page