943,685 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 3073
  • JSP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jul 28th, 2008
0

error while forwarding page

Expand Post »
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
JSP Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Jul 28th, 2008
0

Re: error while forwarding page

Kindly help me.
Thanks and regards
Haresh
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Jul 28th, 2008
0

Re: error while forwarding page

It is YOUR school work/work project so deal with it if you ignore advice from others with more experiences!
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Jul 29th, 2008
0

Re: error while forwarding page

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
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Jul 29th, 2008
-1

Re: error while forwarding page

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...
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Jul 29th, 2008
0

Re: error while forwarding page

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
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Jul 29th, 2008
-1

Re: error while forwarding page

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)?
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Jul 29th, 2008
0

Re: error while forwarding page

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
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008
Jul 29th, 2008
-1

Re: error while forwarding page

Can you get me full table descriptions with indication of primary keys? (Just table structure, not interested in data inside table)
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Jul 29th, 2008
0

Re: error while forwarding page

Hi peter_budo;
here is my table structure of database:

JSP Syntax (Toggle Plain Text)
  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
Reputation Points: 8
Solved Threads: 0
Light Poster
guravharsha is offline Offline
42 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: general questions about jsp
Next Thread in JSP Forum Timeline: Open Office document in IE browser





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC