473,508 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem regarding sessions in jsp

40 New Member
The following is the front end code for searching ,
it takes data and searches from the database by the second code[b].

FRONT END CODE:

Expand|Select|Wrap|Line Numbers
  1.  <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4.  
  5. </head>
  6. <title>
  7. <BODY BACKGROUND="C:\RASE\sample\blue.jpg">
  8.  
  9. <p align="center">
  10. <img border="0" src="C:\Documents and Settings\User\WebApplication1\web\sample\SEARCH1.jpg" width="887" height="141" align="left">
  11.  
  12.  
  13. <p align="center">  
  14.  
  15.  
  16. <p align="center">
  17.  </p>
  18. <p align="center">
  19.  </p>
  20. <p align="center">
  21.  </p>
  22. <p align="center">
  23.  </p>
  24. <p align="center">
  25.  
  26.         <form action="searchser2.jsp" method="post">
  27.         <input type="text" name="T1" size="28">                                                                                     
  28.  
  29.  
  30.  
  31.     <p align="center"> 
  32.  
  33.  
  34.     <p align="center">[font=Algerian][size=6][color=#e19117]STUDENT/ADMINISTRATOR[/color][/size][/font]
  35.  
  36.  
  37.     <p align="center">  
  38.  
  39.  
  40.  
  41. </body>
  42.  
  43. </html>
  44.  
  45.  


SECOND CODE:

Expand|Select|Wrap|Line Numbers
  1.  <%@ page import="java.sql.*" %>
  2. <%!
  3.     String str="";
  4.     String didmean;
  5.     String dd;
  6.     String array[];
  7.  
  8.     int i;
  9. %>
  10.  
  11. <%
  12.                str=request.getParameter("T1");
  13.              didmean="%"+str+"%";
  14.                dd=str;
  15.                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  16.            Connection con=DriverManager.getConnection("jdbc:odbc:mybean","scott","tiger");
  17.            PreparedStatement st=con.prepareStatement("select * from search where fname like ? or fname=? or lname=? or reg=? or year=? or dob=? or cno=? or email=? or agg=?");
  18.            st.setString(1,didmean);
  19.             st.setString(2,str);
  20.              st.setString(3,str);
  21.               st.setString(4,str);
  22.                st.setString(5,str);
  23.                 st.setString(6,str);
  24.                  st.setString(7,str);
  25.                   st.setString(8,str);
  26.                    st.setString(9,str);
  27.  
  28.                     ResultSet rs=st.executeQuery();
  29.  
  30.  
  31.  
  32.                    while(rs.next()) 
  33.                        {
  34.                         String fname1=rs.getString(1);
  35.                         String lname1=rs.getString(2);
  36.                         String reg1=rs.getString(3);
  37.                         String year1=rs.getString(4);
  38.                         String add1=rs.getString(5);
  39.                         String dob1=rs.getString(6);
  40.                          String job1=rs.getString(7);
  41.  
  42.                         String ncompany1=rs.getString(8);
  43.                         String jobplace1=rs.getString(9);
  44.                         String joinedon1=rs.getString(10);
  45.                         String sal1=rs.getString(11);
  46.                         String ninst1=rs.getString(12);
  47.                         String course1=rs.getString(13);
  48.                         String stdplace1=rs.getString(14);
  49.                         String coursecomp1=rs.getString(15);
  50.                          String cno1=rs.getString(16);
  51.                         String email1=rs.getString(17);
  52.                         String agg1=rs.getString(18);
  53.                         String anyother1=rs.getString(19);
  54.                         String option=rs.getString(20);
  55.  
  56.  
  57.                         session.setAttribute("firstname",fname1);
  58.                     session.setAttribute("lastname",lname1);
  59.                     session.setAttribute("regno",reg1);
  60.                     session.setAttribute("yearpassed",year1);
  61.                     session.setAttribute("Address",add1);
  62.                     session.setAttribute("dateofbirth",dob1);
  63.                     session.setAttribute("job",job1);          
  64.                     session.setAttribute("namecompany",ncompany1);
  65.                     session.setAttribute("placeofjob",jobplace1);
  66.                     session.setAttribute("dateofjoin",joinedon1);
  67.                     session.setAttribute("salary",sal1);
  68.                     session.setAttribute("nameofinst",ninst1);
  69.                     session.setAttribute("instcourse",course1);
  70.                     session.setAttribute("placeofstudy",stdplace1);
  71.                     session.setAttribute("completionofcourse",coursecomp1);
  72.                     session.setAttribute("contactno",cno1);
  73.                     session.setAttribute("emailid",email1);
  74.                     session.setAttribute("aggregate",agg1);
  75.  
  76.                     if(option.equals("full"))
  77.                         {
  78.                           if(job1.equals("job"))
  79.                               {
  80.  
  81.                                 out.println("<a href='detailsjob.jsp'>"+fname1+"   "+reg1+"
  82. "); 
  83.  
  84.                               }
  85.                               else if(job1.equals("studies"))
  86.                                   {
  87.                                      out.println("<a href='detailsstudies.jsp'>"+fname1+"   "+reg1+"
  88. "); 
  89.                           }
  90.                            if(job1.equals("both"))
  91.                           {
  92.                                out.println("<a href='totaldetails.jsp'>"+fname1+"   "+reg1+"
  93. "); 
  94.                           }
  95.                           }
  96.                        else if(option.equals("partial"))
  97.                            {
  98.  
  99.  
  100.  
  101.  
  102.                               if(job1.equals("job"))
  103.                               {
  104.                                  out.println("<a href='pdetailsjob.jsp'>"+fname1+"   "+reg1+"
  105. "); 
  106.                               }
  107.                               else if(job1.equals("studies"))
  108.                                   {
  109.                                      out.println("<a href='pdetailsstudies.jsp'>"+fname1+"   "+reg1+"
  110. "); 
  111.                           }
  112.                               if(job1.equals("both"))
  113.                           {
  114.                                out.println("<a href='totaldetails.jsp'>"+fname1+"   "+reg1+"
  115. "); 
  116.                           }
  117.  
  118.                            }
  119.  
  120.  
  121.  
  122.  
  123.                        }
  124.                                        con.close();
  125.                     %>

PROBLEM:

I want to display the results which are there in result set by using sessions.
The above mentioned second code is used to get the records from database.
SO if only one record is obtained it is giving the correct result,but if more then one is retrived it is giving the result of last session which is retrived from database.
So we want to get the apt data for the corresponding achor tag clikced on.
Kindly expecting the reply as soon as possible......
Feb 22 '08 #1
2 1494
Dököll
2,364 Recognized Expert Top Contributor
hummm...

I could be wrong but what if if you select * and do not add any additional constraints, as to returning every single value as opposed to saying like lname & or lname like. I suspect your session should stay alive regardless. Perhaps the select statement is the cause!

Give that a whirl;-)
Dec 12 '08 #2
r035198x
13,262 MVP
The select statement is fine. The problem is overwriting the session variables at every run of the while loop. Better create an HTML table representing the data in the while loop and output that.
P.S Connecting to databases inside JSPs is a big nono.
Dec 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
677
by: Ben | last post by:
Hi, I am running a simple application dedicated to verify the sessions variables, but it is not working. both transid and trackvars are enabled. testpage1: <?php session_start();...
9
2622
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
6
1375
by: Paul | last post by:
Hi all, I seem to been having a problem with sessions. I have a session in the login page Session("UserLevel") = (MM_rsUser.Fields.Item("Accesslevel").Value) which doesn't seem to be visible...
2
1694
by: Nitin | last post by:
Hi, I login to my asp.net web application from the same client machine twice, using different credentials. Both separate instances work fine, independant of each other. However, when I logout...
17
5176
by: jensen bredal | last post by:
Hello, i'm struggling with a somehow badly understood session scenario. I provide acces to my pages based on form authentication using Session cookies. Som of my pages are supposed to be...
2
1364
by: Mikael Östberg | last post by:
Hello all! I have this login function which doesn't work really well. I tried to do extend the built-in functionality in order to store things such as userName and email address in Session. ...
2
1614
by: Dean R. Henderson | last post by:
For an ASP.NET web application, is there a way for one session (with appropriate security authorization) to set a HttpSessionState variable to point to another session and execute the Abandon...
4
4058
by: Ian Davies | last post by:
Hello I am struggling for a solution to clear some fields on my webpage that takes their values from some sessions My solution below works when the button is clicked twice. I sort of know why I...
0
1765
by: TigrouMeow | last post by:
Hello, I'm trying to make a "clean" webservice, using Nhibernate. I'm facing some issues, but i'm quite the beginner with that kind of system. When there are more than 2 clients connected on my...
0
7132
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
773
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.