• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error while forwarding page

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kindly help me.
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"yemyemyes m",
Please check your private messages regarding an important administrative matter.
-Ben
 
Harshal Gurav
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is wrong with above code?
regards
Harshal
 
mohanasundaram muthukannan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic