codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Passing a resultset from a servlet to JSP  Intsik at 04:53 on Thursday, October 28, 2004
 

i have a form that lets a user login.

the login name is being passed to a servle that will generate a query of everything pertaining to her account.

my problem is how to pass the result of the query to a third JSp that will display the information.

I have done the display using the a servlet, but somehow i want to separate the presentation from logic (which i think is a good practice).

Anyone? i will greatly appreciate it...

thanks...

  Re: Passing a resultset from a servlet to JSP  glamgirl at 20:25 on Friday, January 07, 2005
 


I'm not sure if I understand your question correctly, but you can pass variables, or even a collection to a jsp by setting request attributes like this:

request.setAttribute("results", variable);

-e



  Re: Passing a resultset from a servlet to JSP  ladygaga at 08:00 on Tuesday, June 14, 2011
 

red peep toe shoes
black platform sandals
white wedge sandals
cheap wedges
pink glitter pumps
fake christian louboutin
fake christian louboutin shoes


  Re: Passing a resultset from a servlet to JSP  mallory at 17:45 on Thursday, June 16, 2011
 

1. package com.choral.be;
2.
3. import com.oreilly.servlet.MultipartRequest;
4. import java.io.File;
5. import java.io.FileInputStream;
6. import java.io.IOException;
7. import java.io.OutputStream;
8. import java.io.PrintWriter;
9. import java.sql.Connection;
10. import java.sql.DriverManager;
11. import java.sql.ResultSet;
12. import java.sql.Statement;
13. import javax.servlet.RequestDispatcher;
14. import javax.servlet.ServletConfig;
15. import javax.servlet.ServletContext;
16. import javax.servlet.ServletException;
17. import javax.servlet.http.HttpServlet;
18. import javax.servlet.http.HttpServletRequest;
19. import javax.servlet.http.HttpServletResponse;
20. import javax.servlet.http.HttpSession;
21. import oracle.sql.BLOB;
22. import oracle.jdbc.driver.OracleDriver;
23. import oracle.jdbc.OracleResultSet;
24.
25. public class addCandidate extends HttpServlet
26. {
27. public void service(HttpServletRequest req,HttpServletResponse res)
28. throws ServletException,IOException
29. {
30. System.out.println("1");
31. HttpSession session = req.getSession(true);
32. PrintWriter out = res.getWriter();
33. MultipartRequest multi = new MultipartRequest(req, "C:\\TEMP");
34. ServletConfig config = null;
35. ServletContext context = null;
36. RequestDispatcher rd = null;
37. try{
38. System.out.println("2");
39. config = getServletConfig();
40. context = config.getServletContext();
41.
42. }catch(Exception e)
43. {
44.
45. }
46. String firstname = multi.getParameter("fname");
47. String lastname = multi.getParameter("lname");
48. String dt1 = multi.getParameter("dob1");
49. String dt2 = multi.getParameter("dob2");
50. String dt3 = multi.getParameter("dob3");
51. String dateofbirth = dt1 + "-" + dt2 + "-" + dt3;
52. String p1 = multi.getParameter("ph1");
53. String p2 = multi.getParameter("ph2");
54. String phone = p1 + " " + p2;
55. String mail = multi.getParameter("email");
56. String qualification = multi.getParameter("qualification");
57. String skills = multi.getParameter("skill");
58. String company = multi.getParameter("company");
59. String designation = multi.getParameter("desgn");
60. String e1 = multi.getParameter("exp1");
61. String e2 = multi.getParameter("exp2");
62. String experience = e1 + "." + e2;
63. String salary = multi.getParameter("salary");
64. String location = multi.getParameter("location");
65. String dappf = multi.getParameter("desgnappfor");
66. String expsal = multi.getParameter("expsal");
67. String saloff = multi.getParameter("saloff");
68. String r1 = multi.getParameter("rst1");
69. String r2 = multi.getParameter("rst2");
70. String result = r1 + " " + r2;
71. String id1 = multi.getParameter("id1");
72. String id2 = multi.getParameter("id2");
73. String id3 = multi.getParameter("id3");
74. String intdate = id1 + "-" + id2 + "-" + id3;
75. String comments = multi.getParameter("comments");
76.
77. String sql1 = "select first_name,last_name,to_char(date_of_birth,'DD-MM-YYYY')"
78. +" from interviewee where first_name = '"
79. +firstname+"' and last_name = '"+lastname+"' and date_of_birth = to_date('"
80. +dateofbirth+"','DD-MM-YYYY')";
81.
82. String sql2 = "select first_name,last_name,to_char(date_of_birth,'DD-MM-YYYY'),phone,"
83. +"email,qualification,skill_set,company,designation,experience,salary,location,"
84. +"designation_applied_for,expected_salary,salary_offered,result,"
85. +"to_char(interview_date,'DD-MM-YYYY'),comments from interviewee where first_name = '"
86. +firstname+"' and last_name = '"+lastname+"' and date_of_birth = to_date('"+dateofbirth+"','DD-MM-YYYY')";
87.
88.
89. String sql = "insert into interviewee values('"+firstname+"','"+lastname+"',to_date('"+dateofbirth+"','DD-MM-YYYY'),'"
90. +phone+"','"+mail+"','"+qualification+"','"+skills+"','"+company+"','"
91. +designation+"','"+experience+"',"+salary+",'"+location+"','"+dappf+"','"
92. +expsal+"','"+saloff+"','"+result+"',to_date('"+intdate+"','DD-MM-YYYY'),'"
93. +comments+"',empty_blob())";
94.
95. String sql3 = "select cv from interviewee where first_name='"+firstname+"' and last_name='"
96. +lastname+"' and date_of_birth=to_date('"+dateofbirth+"','DD-MM-YYYY') for update";
97.
98. try
99. {
100. System.out.println("3");
101. Class.forName("oracle.jdbc.driver.OracleDriver");
102. Connection con = DriverManager.getConnection("jdbc :-o racle:thin:@10.11.32.86:1521:Resumedb","scott","tiger");
103. con.setAutoCommit(false);
104. Statement stmt = con.createStatement();
105. System.out.println("32");
106. ResultSet rs = stmt.executeQuery(sql1);
107.
108. if(rs.next())
109. {
110. System.out.println("4");
111. res.sendRedirect("/forum/addError.html");
112. System.out.println("5");
113. }else
114. {
115. System.out.println("6");
116. stmt.executeUpdate(sql);
117. System.out.println("7");
118. rs = stmt.executeQuery(sql3);
119. System.out.println("8");
120. rs.next();
121.
122. BLOB blob = ((OracleResultSet)rs).getBLOB("cv");
123. File file = multi.getFile("cv");
124. FileInputStream input = new FileInputStream(file);
125. OutputStream output = blob.getBinaryOutputStream();
126. int size = blob.getBufferSize();
127. byte[] buffer = new byte[size];
128. int length = -1;
129. System.out.println("9");
130. while ((length = input.read(buffer)) != -1)
131. output.write(buffer, 0, length);
132. input.close();
133. output.close();
134. System.out.println("10");
135. rs = stmt.executeQuery(sql2);
136. System.out.println("11");
137. if(rs.next())
138. {
139. System.out.println("12");
140. rd = context.getRequestDispatcher("/jsp/addSuccess.html");
141. rd.forward(req,res);
142. System.out.println("13");
143. }else
144. {
145. res.sendRedirect("/jsp/addFail.html");
146. }
147. }
148.
149. }catch(Exception e)
150. {
151. out.println(e);
152. }
153. }
154. }


Web Solution India








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Help with 2 level tab menu
•  Re: Using Javascript to create simple tabs
•  Re: How to open a MS Word document from Javascript
•  Re: Help: Trouble with z-Index and SELECT lists
•  Re: Web Designing Companies in Chennai
•  Why should you attend Apache Lucene EuroCon 2011
•  Re: Saving a Picture or Image contained within a Picturebox into Windows Registry
•  Re: Write text strings to Serial Port
•  Re: Passing a resultset from a servlet to JSP


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2011