0

For my college project I have to build a custom JSP/Servlet MVC application so I can't use frameworks such as Struts or Spring. I already have FrontController, Command, Service, DAO, Business layers.

Let's say I want to create a website with a sidebar and in the sidebar has the following widgets: Members, Who's Online, Recent Comments. Each widget accesses the database via Command -> Service -> Dao.

I want information to be displayed in the sidebar constantly throughout the application. Problem is I don't know how to do this. I know how to display information by processing GET/POST requests but I don't know how to display information (from database) without GET/POST requests if that makes sense?

Couple of ways I tried that don't work:

1) Upon loading the homepage and invoking the HomeCommand calls ListUsers from UserDao and then stores them into a session. But if the user enters the site from a different URL ListUsers won't be stored into a session.

2) Creating a separate Command: MembersCommand, WhosOnlineCommand, RecentCommentsCommand. Then use JSTL include to include the FrontController and to get it to invoke the Command. But include wants a .jsp

<jsp:include page="FrontController/members" /> 
Fragment "FrontController/members" was not found at expected path /MyApplication/WebContent/WEB-INF/FrontController/memmbers

3) Create individual .jsp's for each widget (members.jsp, whosonline.jsp) with Java code to access the Dao. Then use JSTL include. But how would I get it to go through the FrontController and isn't Java in jsp's a big no-no?

4) Use <jsp:forward page="" /> but this gives me a blank page?

I'm out of ideas?

Jonathan
  • 3,016
  • 9
  • 43
  • 74

2 Answers2

0

I didn't understand all of what you are trying to say, but perhaps a servlet design pattern can help. Typically with a front controller, you access your persistent storage, and then store what you need to store in "session" or "request" scoped areas. However, since you talked about "another web site" I think you may need to store your data in the "application" type area. If you are using a servlet as a front controller, this area is accessed by getServletContext().setAttribute() and later your JSP page can just access the variable the same way as it does to session-scoped variables. I couldn't tell if your front-controller was a servlet or a JSP, but it doesn't matter because both are able to store application-scoped variables.

In a real business environment, this is not sufficient, because servlets are often shared amongst multiple machines, and can be re-started and stopped many times; and therefore any persistent information would have to be retrieved directly from the database. However, for a project, storing data in application-scoped variables is sufficient.

I know I missed a good part of what you were explaining, but my point is a front controller accesses (several) persistent storages, loads up all the data needed for the returned jsp pages into session or request or application variables(in this case) and the jsp file can be written to make use of all the data that had been stored in these variables.

SunKing2
  • 311
  • 2
  • 10
0

check this tutorials for MVC architecture for java web applications. hope you can get some insight

http://www.javaranch.com/journal/200603/frontman.html

Design Patterns web based applications

http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html

Show JDBC ResultSet in HTML in JSP page using MVC and DAO pattern

Community
  • 1
  • 1
mykey
  • 575
  • 2
  • 10
  • 24