• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

returning a resultset

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to view output from a query on table in formatted ways as I like then what I am doing is calling a servlet from jsp , this servlet calls another jsp which in turn execute a query through a bean.
This bean methods return whole resultset to jsp page.

And In jsp I am using rs.getString(1),...... like this . where I need a value.
How can model view control can be applied to this? Need a good approach from java guru's
thanks in advance
payal sharma
 
payal sharma
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got the answer.I will put the resultset in to session and open the jsp page which will take the resultset from the session.
payal sharma
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ack!
You put a database resource in the session?
I really can't say I agree with that at all...
The way I usually do it is read from the database and populate the data into Business Objects (essentially an object with a one to one relationship to a database row) then pass either a single or java.util.Collection of these Business Objects to the JSP for presentation.
Dave.
 
payal sharma
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David
Please explain in detail what you mean by business object.
Could you please explain in detail if possible.
2)
I am also getting problems with session
I am using tomcat 3.1
In my login page my session value get lost frequently.I am using session.setAttribute("logon.isDone", name); in servlets and In every jsp's I am checking as <% if(session.getAttribute("logon.isDone")==null){
response.sendRedirect("/iscap/report/relogin.jsp");}%>
The value get lost in a very short time so user is sent to relogin .

payal sharma
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At some stage in an MVC based site you need the model, the representation of the business logic for the site.
There are several ways of accoplishing this, using EJBs etc and any site on MVC will discuss this for you, but basically you're looking for some way of passing data from your persistance level (database etc) via the business level to the presentation level of your application.
If you pass the ResultSet to the JSP then you are giving the presentation level knowledge about the persistance mechanism.
If you have a db table holding user info, username, userID, email etc then create an object that represents this data. Read from the database into these objects then pass these objects (via request.setAttribute() rather than writing to the session) to the JSP.
That's the short answer.
With respect to the session problem, sessions are supported in the browser using cookies so you might look at your browser settings. You might want to post some sample code cos it could also be Thread problems or that you're just allowing your code to over write the data...

Dave.
 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David, I am reading Wrox's Java Server Programming J2EE. The authors doesn't seem mind putting DataSource as one of the SessionBean's properties. What is your view on that?
Also, how do we synchronize(session) in JSP like we do in servlets? By making SessionBean's every method synchronized?
payal, you may also want to check your web.xml to see if the session duration was set too short.
Thanks.
[This message has been edited by Cameron Park (edited August 27, 2001).]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My main problem is that if the ResultSet gets put on the Session then how do you release the related Connection or Statement? What if you release the Connection in the Servlet but it gets reassigned from the pool before you use the ResultSet etc etc.
It might be that the Wrox people were doing so for simplicity cos they tend to write a heap of code in their books (I'm reading the same book at the moment and enjoying it immensely )
Anyway, I disagreed with the Payal was doing things since it could cause resource problems. To solve smaller problems it may be worthwhile cutting corners to get a solution, but personally if you're going to do it, using a proven solution (MVC, separation of levels etc) is always a good idea.
So personally, I'd never place persistence layer information anywhere that the presentation layer could access it...
Dave.
 
payal sharma
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks david for pointing the connection and statement problem which would be return to connection pool before getting result.
cameron, Session problem is very strange to me.If I enter 10 reports then in 2 I got this problem of values in session get lost.So user complain that his values are null sometimes.
I am giving sample code of one of my process which set values
<%@ page import="java.util.*,report.Report1"%>
<jsp:useBean id="report1" scope="session" class="report.Report1" > </jsp:useBean>
<jsp:setProperty name="report1" property="reset" value=" " />
<jsp:setProperty name="report1" property="*"/>
<% if(session.getAttribute("logon.isDone")==null){
response.sendRedirect("/report/relogin.jsp");}%>

<% String sitename=""; %>
<% sitename=(String)session.getAttribute("logon.isDone"); %>
<% if(sitename.equalsIgnoreCase("Bombay")) {%>
<% sitename="mumbai"; %>
<% } %>
<% String entersite=""; %>
<% entersite=report1.getSite(); %>
<% if(entersite.equals(sitename)) { %>
<% if (report1.validate()) { %>
<jsp:forward page="/report/report2.jsp"/>
<% } else { %>
<jsp:forward page="/report/report1.jsp"/>
<% } %>
<% } else { %>
<jsp:forward page="/report/please.jsp"/>
<% } %>

detail of my app is
I am making an online reporting site .I am asking user to fill 3 page
report one by one .I am keeping all value in session.Here Also checking at
every servlet and jsp whether user is valid or not as guest can see the
report but can not fill the report.
A valid user can upload database and only administrator can download
database files.
There are also other simple report to be filled on the site.
These all report are to filled fortnightly and if user miss then he should be
emailed from the server .
I had made this in servlets,jsp,javabeans(with set and get methods only)
Problem I always facing that my session value get lost very easly and
user is sent back to login page . An example
I am using tomcat 3.1
In my login page my session value get lost frequently.I am using
session.setAttribute("logon.isDone", name); in servlets and In every jsp's
I am checking as
I have taken all initiative to build this site.I am the only programmer
working here so all decision is up to me.

thanks in advance
payal sharma
 
My honeysuckle is blooming this year! Now to fertilize this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic