File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

From where request is made?

 
Em Aiy
Ranch Hand
Posts: 226
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?
 
Richard Green
Ranch Hand
Posts: 536
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getRequestURI()
 
Em Aiy
Ranch Hand
Posts: 226
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well, i have checked that, but it is either giving me the NULL value or giving me the value of the servlet that has recieved request ...

my, signUp.html is requesting to navigationServlet, and when i print the request.getRequestURI() it prints the
http://127.0.0.1:8084/siteName/NavigationServlet ... !
[ August 21, 2006: Message edited by: Muhammad Ali Amin ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This will return null if someone types the URL in by hand or uses a bookmark.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And browsers are not required to set it, so it is not reliable
 
Em Aiy
Ranch Hand
Posts: 226
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:


This will return null if someone types the URL in by hand or uses a bookmark.


so if it returns null, if we types the URL, then how can we use it at runtime to check from where the request is made.

??
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Em Aiy
Ranch Hand
Posts: 226
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want to know is there any build in mechanism in JAVA(request, response)

I don't think there is, except setting a parameter, or calling different controllers for each action.
 
Em Aiy
Ranch Hand
Posts: 226
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting the parameter --- is the approach right now i am using
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 1847
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Em Aiy
Ranch Hand
Posts: 226
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.


P.S:

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?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic