I am making a project, in which it is demand that there should be one servlet "navigationServlet" which should handle all the navigation of the web. I have to redirect the request to specific servlets, but sometimes i have to make decision depending on the situation from where the request has been made.
Is there any way to find it out from where the request has been made? right now i am using session to store the current page being displayed (i am not using query string for this purpose). Can you people tell me any good solution?
The difference between <b>failure</b> and <b>success</b> is often being <b>right</b> and being <b>exactly right</b>.
request.getRemoteAddr() will give you the IP address from which the request was received. There's a request header "user-agent" which will tell you (if it's set) what the client claims to be (which is not what it actually is, as many non-browser clients and some browsers fake that header get get past certain firewalls that block all http traffic not coming from IE or Netscape derived browsers).
I think you need to clarify what you mean by "From where the request is made".
Are looking for the IP number of the client that made the request or are you looking for the page that contained the link or form that the user clicked to generate the request to your servlet?
Joined: May 11, 2006
i am sorry for not making things clearer. WEll i want to know from which page the request is being generated.
i.e i am having a link say "A" on pageA and pageB ... if the link is clicked via pageA i have to goto some version say AXX and if the link is clicked from pageB i have to go some version say AYY.
I have set the link values in DB, so i can't put the link in HTML while generating it since for value A i am having link A in DB ... the value XX and YY are being genreated at runtime depending upon the page from it is being clicked.
I know i can handle it using the queryString by adding a form and a hidden field, but i want to know is there any build in mechanism in JAVA(request, response)?
Originally posted by Muhammad Ali Amin: Setting the parameter --- is the approach right now i am using
Why the sad face? It's the right way to do it. Trying to figure out where the page was invoked from in order to branch on processing was a really poor design choice. By doing so, you would have created a lot of implicit bindings and co-dependencies among your pages that would make them confusing and fragile.
Think about it from the point of view of Java methods. To cause a method to branch on processing, do you inspect the stack trace to figure out from where the method was called? Of course not. That would be ridiculous. Rather, you pass a parameter to the method that causes it to act in the manner that the caller desires.
To bring back a smile, I'd like to add that Spring is actually using hidden parameters for its WizardForms. One indicating the current page, one indicating the target page.
(I am not saying that because Spring does it this way, then you should do it the same way )
Jeroen T Wenting
Joined: Apr 21, 2006
It's not a bad system. In fact it's the logical solution. The alternative would be to have a database of some sort to store every possible combination of origin-destination and have each page contain keys into that database for each button or link that goes to another page.
I've used both in the past, both work well.
Joined: May 11, 2006
thanks for your comments.
Well, actually it was first time that i am designing the application beside coding it. That's why i was thinking about the most flexible and good design. I don't know the design i have done is right or not. That's why i wanted to discuss what i have implemented.
Can you people suggest me how can i evaluate my design? Should i post the real requirement with the design i opted for in some topic here?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com