• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Managing URLs and bookmarks in Struts

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

As I've been working with Struts for a little while, I've noticed something. It's almost like working with frames sometimes. I can have a page, say a user details page. The request goes from a JSP to the action then to a details JSP. The URL is not unique for that user.

If a user wants to bookmark that page, the bookmark won't work the next time they use it.

Is there a way to make this work? Something I can change?

TIA
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Using the Struts framework does not prevent a user from bookmarking a page. It's just that the action is bookmarked rather than the JSP.

For example, if you have an action customerHomeInit that forwards to customerHome.jsp, and the customer bookmarks the page, the URL in the bookmark will be http://www.mycompany.com/myapp/customerHomeInit.do.

In a web application, where you have a flow that the user is supposed to follow, anticipating that the user may bookmark one of the pages and handling it is part of your development strategy.

In the above example, suppose that a user isn't supposed to access the customer home page unless they're logged on. It's up to the developer to put logic in the customerHomeInit action to check for a valid logon and either give an error message or redirect back to the logon page.
[ February 22, 2006: Message edited by: Merrill Higginson ]
 
Wes Sorensen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I appreciate the reply, and in many situations, bookmarking the action is fine. My question is, say you have a page with a search button on it. You type in your search criteria and the JSP goes to your action which build a bean of the results and then through an ActionForward sends to the JSP to display the results.

The bookmark will just be the search.do action, so bookmarking that page of results will not be helpful since the bean of results will not be there next time.

What's the solution?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the serach.do action is invoked from a bookmark instead of from the action of a previously displayed form, none of the input fields on the form bean will have values.

The solution is to have the search action look for this condition and if it occurrs, forward to the search input page instead of the search results page.
 
Wes Sorensen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill. I was thinking that in a normal JSP -> JSP you might just send it as URL parameters and then a bookmark would work. I suppose it might still work OK like this in Struts, but I'm not positive.

I may have to continue to play with it some. I'm just trying to make it easy for my users to send links to another person and have it work. I guess if I sent it over using URL parameters...

ie: www.mycompany.com/showUserDetails.do?userid=15

or www.mycompany.com/searchResults.do?param=criteria
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you specify method="GET", within the <html:form> tag, the search parameters passed will be included in the URI, and will therefore be included if the user bookmarks the page.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right,
Perhaps you are not getting the previous search page thru bookmark as your URL does not contain the input parameters that you have used.

Parameters will be added to the URL if you use HTTP GET method.
Try using it and I am sure you will see what you need.
 
Wes Sorensen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the suggestions. I'll send it via GET instead. Probably a question that should be in the servlet forum, but quickly, is there a guideline on when GET should be used over POST (other than already discussed)? Sorry, probably a very basic servlet question...
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main difference between the get and post methods is visibility. Get passes parameters in the URI, while post passes them in the HTTP headers. In some cases, such as when you're uploading a file, Post is your only option, and generally speaking, post is the best option when using forms. You generally don't want everything that's passed by your form to be visible in the URI.

However, in a case like this where you're doing a serach and you want the search parameters to be visible and available for bookmarking, get is the better option.
 
Wes Sorensen
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perfect! Thank you Merrill & Jitender! I appreciate your help!
 
You got style baby! More than this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic