File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error while forwarding page

 
Harshal Gurav
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kindly help me.
 
Matteo Di Furia
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"yemyemyes m",
Please check your private messages regarding an important administrative matter.
-Ben
 
Harshal Gurav
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should close you're Connection object.


But I dont think that will stop the forward
 
mohanasundaram muthukannan
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2851
10
Fedora Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mohanasundaram muthukannan
please UseCodeTags.
You can add code tags by clicking the button.
 
Harshal Gurav
Ranch Hand
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is wrong with above code?
regards
Harshal
 
mohanasundaram muthukannan
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 151
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your post.
and Yes, i can use variable by closing the resultset first.
Thanks again
regards
harshal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic