aspose file tools*
The moose likes Servlets and the fly likes In a MVC design is it possible to automatically invoke a Command upon page load? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "In a MVC design is it possible to automatically invoke a Command upon page load?" Watch "In a MVC design is it possible to automatically invoke a Command upon page load?" New topic
Author

In a MVC design is it possible to automatically invoke a Command upon page load?

Jonny Devine
Greenhorn

Joined: Feb 08, 2012
Posts: 6
I'm using a MVC pattern for my application. It has a FrontController, Command, Service, and DAO. For my application to process requests/responses it has to send a command to the FrontController - this is usually done via get/post requests.

The problem im having is that I want to display a list of users (and their avatars) on my homepage. How do I get my jsp page to automatically call the ListMembers command upon page load without get/post request?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Your home page is displayed without the use of a GET or POST request? I don't think so.

The display of your home page should be the result of a command like any other request.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jonny Devine
Greenhorn

Joined: Feb 08, 2012
Posts: 6
Bear Bibeault wrote:Your home page is displayed without the use of a GET or POST request? I don't think so.

The display of your home page should be the result of a command like any other request.


That's the thing, I don't know how it works? When the user goes to www.website.com/index I want to display a list of members. It works when the user goes to www.website.com/index?action=ListMembers but I want it to work when the user just goes to the index page without any parameters in the URL? How do I get the command "ListMembers" to be invoked upon index page load?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

You need to find out what /index is mapped to. Do you really mean /index? Or do you really mean /index.jsp?

You may want to check the deployment descriptor for a mapping of /index or a welcome-file declaration.
Jonny Devine
Greenhorn

Joined: Feb 08, 2012
Posts: 6
Bear Bibeault wrote:You need to find out what /index is mapped to. Do you really mean /index? Or do you really mean /index.jsp?

You may want to check the deployment descriptor for a mapping of /index or a welcome-file declaration.


Sorry I meant /index.jsp. My FrontController strips the .jsp.

So in order for my index.jsp page to invoke the ListMembersCommand upon page load I have to add a mapping to the deployment descriptor to presumably a servlet? Thing is ListMembersCommand is not a servlet. Only my FrontController is a servlet and that is already mapped in the DD. Am I getting that right?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

Make sure that there is no index.jsp page, and then add the URL to the homepage's action as the welcome-file. If someone types the URL without a path, they will be directed to the home page command. If they type index.jsp, they'll get a 404 like they should.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In a MVC design is it possible to automatically invoke a Command upon page load?