This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HTML -> Servlet -> java bean -> JSP  RSS feed

 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,
I have to work on a model when the user logs into HTML page the control from here goes to
a servlet which does the business logic by calling java beans. After getting the result from
these java beans the servlet displays the result in a JSP.
Can anybody help me by providing code(especially the servlet code) for this kind of a model
Thanks
Neha
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Neha!
Here is the Servlet code...
public void service(HttpServletRequest objRequest, HttpServletResponse objResponse)
throws ServletException, IOException
{
String strUserId;
String strCount;
m_vctAccountStatusBeans.clear();
HttpSession objSession = objRequest.getSession(true);
objResponse.setContentType("text/html");
strUserId = objRequest.getParameter("userID");//Data from HTML
System.out.println("SvltController--> userID from request "+strUserId);

//Set Data here in ur value bean and keep it in session
//Code for Setting values....You have to include here
objSession.setAttribute("AccountBean",AccountStatusBeans);
//Display results in this page....
objResponse.sendRedirect("URL FOR THAT PAGE");
}

This particular thing is similar to MVC Architecture a very good one..
One more thing...Try to avoid post a question in a Forum regsding complete code...
Rgds
Manohar
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Manohar,
Here you are putting the bean itself in the session. why would we do that is there any reason for that. because that way I'm not able to figure what will be the use of a servlet then. as then the bean will be used in the JSP just like the regular JSP bean communication.
Say If my bean returns a resultSet I want to send that resultset object in my response to the JSP. How in the JSP, can I use this resultset object.
Neha
 
Manohar Karamballi
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Neha!
U r query sounds like something worthy to spend time over it.. But can u elaborate more on what ur saying? I didn't understood exactly what ur saying. May be requirements are diifferent in both of cases...
Rgds
Manohar
 
Mahesh Kulkarni
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Neha,
Put resultset in the session and retrieve th esame in the JSP
as follows.First you have to put the rs in seesion in a servlet as follows.
session.setAttribute("rs",rs);
JSP code
<%
session = request.getSession (true) ;
rs = (ResultSet)session.getAttribute("rs");
while (rs.next())
{
%>
your table goes here (Presentation)
<%
}
%>
I hope this will help you
Thanx
Mahesh
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With respect to putting the ResultSet on the session, I've said Ack! before and I'll say Ack! again.
Obviously something I feel strongly about
Dave.
 
Manjunath Reddy
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Totally agree with Dave!
Use the paradigm of manohar but limit it to the request scope.
Also look at the peer pattern of MVC model from the book "Database Programming with JDBC and Java(G.Reese), O'Reilly". The book should have been titled "Designing Web Application Persistence and transactions"...
It steps through the design and construction of app's with various tested and proven models while giving an overview of underlying architecture principles.
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David , Manohar, Mahesh Thanks I could do my JSP with your valuable inputs.
Neha
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to you (Manjunath) too. I'm sorry I missed your input before I wrote my previous thanks note.
Neha
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!