aspose file tools*
The moose likes Servlets and the fly likes read from httpRequest put into httpResponse in Filter? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "read from httpRequest put into httpResponse in Filter?" Watch "read from httpRequest put into httpResponse in Filter?" New topic
Author

read from httpRequest put into httpResponse in Filter?

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 550
Hi
Thank you for reading my post
I am looking to understand how I can read something from a httprequest and then add the same parameter to that request httpresponse.
Is it possible to put my own parameters into http header using this way?

for example request A come for filter F and then in filter F I read parameter p from the request A, request will go into endpoint servlet and come back, when it come back I put PP into the response header which is going toward client.

Thanks
[ December 03, 2007: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Parameters and headers are two separate things.
Can you explain, exactly what you are trying to do?
There might be a more standard way of doing it.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 550
Hi
Thank you for reply.
I want to interpert each request to see whether an specefic httpRequest header attribute like request-number is present or not. if it is present I want to store the number and then let the request go to servlet. when the response of this request come back from the servlet I want to increment request-number and let the response go to client.
before i increment the request-number I will check to see what is inside the response.

Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Again form/querystring parameters and HTTP request headers are two different things.

Headers, for the most part, are something that we, as application developers, don't get too involved with. They're generally treated as a low level part of the HTTP protocol.

What are you using for a client? A web browser?
Or have you written something custom?
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 550
Thank you for reply.
I do not want to use QueryString or add changes to real content of the response, But I exchange some values between client (an specific client, it is not a browser) and the server.

The scenario or this exchange is like what I explained in my first post.


Thanks for your time.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Filters are passed references both the request and response objects so you should be able to read and write HTTP headers with:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletRequest.html#getHeader(java.lang.String)
and
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpServletResponse.html#setHeader(java.lang.String,%20java.lang.String)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: read from httpRequest put into httpResponse in Filter?
 
Similar Threads
What's the best practice approach for implementing persistent sessions in Tomcat?
Do I need a separate Web Client?
Controller redirect to another Controller?
RestTemplate - How can I?
@Responsebody for HTTP msg and a View to show the HTTP response msg