error while forwarding page

Thread Solved

Join Date: Jun 2008
Posts: 38
Reputation: guravharsha is an unknown quantity at this point 
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

error while forwarding page

 
0
  #1
Jul 28th, 2008
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. The below code works fine without closing rs
If i had tried to close rs.close(); it show the compile error: rs might not have been initialised.
and without close, it does not work for the accessdenied.jsp
  1.  
  2. <%--
  3. Document : as
  4. Created on : Jul 26, 2008, 12:41:17 PM
  5. Author : user1
  6. --%>
  7.  
  8. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  9. <%@ page language ="java" %>
  10. <%@ page import="java.sql.*, javax.sql.*, javax.naming.*,java.io.*,java.util.*" %>
  11.  
  12.  
  13. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  14. "http://www.w3.org/TR/html4/loose.dtd">
  15.  
  16. <html>
  17. <head>
  18. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  19. <title>JSP Page</title>
  20. </head>
  21. <body>
  22. <%
  23. String userid=request.getParameter("userid");
  24. String password=request.getParameter("password");
  25.  
  26. InitialContext context = new InitialContext();
  27. DataSource ds = (DataSource) context.lookup("java:comp/env/jdbc/mynewdatabase");
  28. Connection conn = ds.getConnection();
  29. context.close();
  30.  
  31.  
  32. Statement stmt=conn.createStatement();
  33. ResultSet rs;
  34.  
  35. try {
  36. rs=stmt.executeQuery("select groupid from user where emailid='"+userid+"' and Password='"+password+"'");
  37. %>
  38. <% while(rs.next())
  39. {
  40. %>
  41. <% String groupId = rs.getString("groupid");
  42. out.println(groupId);
  43. if ( groupId==null )
  44. {
  45. out.println("Invalid User");
  46.  
  47. %>
  48.  
  49. <jsp:forward page="/AccessDenied.jsp" />
  50.  
  51. <%
  52. }
  53. else
  54. {
  55. out.println("Valid User");
  56.  
  57.  
  58. %>
  59. <jsp:forward page="/try.jsp" />
  60. <% }
  61. }
  62. }
  63. finally
  64. {
  65. if (rs != null)
  66. {
  67. rs.close();
  68. rs = null;
  69. }
  70. if (stmt != null)
  71. {
  72. stmt.close();
  73. stmt = null;
  74. }
  75.  
  76. }
  77. %>
  78.  
  79. </body>
  80. </html>


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
Haresh
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 38
Reputation: guravharsha is an unknown quantity at this point 
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

Re: error while forwarding page

 
0
  #2
Jul 28th, 2008
Kindly help me.
Thanks and regards
Haresh
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,272
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: error while forwarding page

 
0
  #3
Jul 28th, 2008
It is YOUR school work/work project so deal with it if you ignore advice from others with more experiences!
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 38
Reputation: guravharsha is an unknown quantity at this point 
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

Re: error while forwarding page

 
0
  #4
Jul 29th, 2008
Hi peter_budo;
I am really sorry for ignoring your precious suggestion.
see why I am doing is that i had just completed java course and in class i had learned about how to connect to database in jsp and I am doing that pattern as i had practiced it in lab.
yes, it seems really difficult to modify the jsp code with database connectivity.

now as per your suggestion whether i have to write separate servlet for database connectivity for each jsp page:
Kindly give me few minutes and tell how can use you suggested theme for above jsp page.
in my jsp project there are nearly 35 jsp pages. so for each jsp page should i require to write separate database connectivity servlet.
Give me details
Waiting for your precious suggestion .
Thanks and regards
Haresh
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,272
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: error while forwarding page

 
-1
  #5
Jul 29th, 2008
If you provide more in detail description of your problem/project then "in my jsp project there are nearly 35 jsp pages" and explain how you got to that conclusion you may actually get some precious suggestions...
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 38
Reputation: guravharsha is an unknown quantity at this point 
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

Re: error while forwarding page

 
0
  #6
Jul 29th, 2008
Hi peter_bodo,
I am developing a project: student feedback system for an institution.
Here each student will get an userid and password .
There are six tables in database to support project
1. User—consist of user information like username, password etc.
2. Groupid—consists of various groups like group of student, group of faculty. Users are divided into various groups.
3. questionid- consists of question of various types. Each question-id consist multiple question
4. Questionbank: consist of large no. of question for particular question-id. Here you can assume question-id=questiontype. Common between above two table is question-id(int).
5. event table—where various event are published. For each event there may be more than one question-id
e.g event—feedback of semester –4-- containing question-id like: question-id for economics batch, question-id for commerce batch
6. Final output table- consist of userid,question-id,question,answer marked by various user.
There are two users. One is normal user and second is system administrator who can add, detete,modify all the questios,user,event, or any module.
So developed the pages for administration add, delete, modify for questionbank, question-id,event,group. So there will be about 15 jsp pages.
Once normal user will log in, it will shows all the event that is marked as published and targeted to the particular group. When it will click on this event it will show the various question-id (consist of various question)available for answering.
The question is in choice format. Like:
1.question name
a.option -A
b.option-B
once user answer all the questions it will stored the final output table.
So I had developed the pages for administrator, also for user to shows various event with question-id, also when user fill all the answer of all question, it will stored in final table.
please dont suggest to change database structure as it is assigned by my boss to me.

I hope it may clear to you.
Thanks and Regard
Haresh
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,272
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: error while forwarding page

 
-1
  #7
Jul 29th, 2008
What are the major views that admin and student get?
Like admin will see some of these options
  • add
  • delete
  • modify
I want to know what exactly is available to them and in what kind of form (links, buttons etc)?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 38
Reputation: guravharsha is an unknown quantity at this point 
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

Re: error while forwarding page

 
0
  #8
Jul 29th, 2008
Hi,
Once student log in he/she will see the link of all event available in table event and marked to that particular group. Once it will click on the that link it will shows the related question-id (question-title) name from question-id table. Once user click on that link it will see all the question belong to the question-id in questionbank table .
Answer of question is in radio-button format for choice a, choice-b which also from option available in questionbank table for respective question . once he/she will mark all question the result will stored in final table.
So view will contain first page- event name from event table click->> retated question-id(question-title) from question-id table click all questions and related options from questionbank table.

Thanks and Regards
Haresh
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,272
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 493
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: error while forwarding page

 
-1
  #9
Jul 29th, 2008
Can you get me full table descriptions with indication of primary keys? (Just table structure, not interested in data inside table)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 38
Reputation: guravharsha is an unknown quantity at this point 
Solved Threads: 0
guravharsha guravharsha is offline Offline
Light Poster

Re: error while forwarding page

 
0
  #10
Jul 29th, 2008
Hi peter_budo;
here is my table structure of database:

  1. CREATE TABLE user
  2. (
  3. userid int(4) NOT NULL auto_increment,
  4. firstname varchar(100) NOT NULL,
  5. lastname varchar(100) NOT NULL,
  6. emailid varchar(100) NOT NULL UNIQUE,
  7. password varchar(50) NOT NULL,
  8. groupid int(8) not null,
  9. PRIMARY KEY ( userid)
  10. );
  11.  
  12. CREATE TABLE markedevent
  13. (
  14. userid int(4) NOT NULL ,
  15. eventid int(4) NOT NULL,
  16. PRIMARY KEY ( userid)
  17. );
  18.  
  19.  
  20. CREATE TABLE Event
  21. (
  22. Eventid int(4) NOT NULL AUTO_INCREMENT,
  23. Description varchar (255) NOT NULL,
  24. Publish varchar(20) NOT NULL,
  25. Questionid int(4) NOT NULL,
  26. Targetgroup varchar(70) NOT NULL,
  27. Anonymous varchar(15) NOT NULL,
  28. PRIMARY KEY ( Eventid )
  29. );
  30. CREATE TABLE Questionid
  31. (
  32. Questionid int(4) NOT NULL AUTO_INCREMENT,
  33. Description varchar(70) NOT NULL,
  34. Type varchar(70) NOT NULL,
  35. PRIMARY KEY (Questionid)
  36. );
  37. CREATE TABLE QuestionBank
  38. (
  39. Qserialno int(3) NOT NULL AUTO_INCREMENT,
  40. Questionid int(4) NOT NULL ,
  41. Questionname varchar(255) NOT NULL,
  42. OptionA varchar(50),
  43. OptionB varchar(50),
  44. OptionC varchar(50),
  45. OptionD varchar(50),
  46. Other varchar(50),
  47. Answer varchar(1),
  48. PRIMARY KEY (Qserialno, Questionid )
  49. );
  50. CREATE TABLE Final
  51. (
  52. Userid int(4) ,
  53. Eventid int(4) NOT NULL,
  54. Questionid int(4) NOT NULL,
  55. Qserialno int(3) NOT NULL,
  56. Answer varchar(8) NOT NULL
  57. );
I had just copied the database creation page.

Thanks and Regards
Harshal
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 2572 | Replies: 24
Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC