File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes doGet() calling doPost() problem -- URL line visible in destination page! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "doGet() calling doPost() problem -- URL line visible in destination page!" Watch "doGet() calling doPost() problem -- URL line visible in destination page!" New topic
Author

doGet() calling doPost() problem -- URL line visible in destination page!

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
I call my Servlet from a JSP page with a dispatcher.forward(request, response).
What gets executed in the Servlet is the doGet().
OK.
The problem is that when I pass the doGet() in the Servlet on to the doPost() in the Servlet (with doPost(request, resposne) and the servlet's doPost() forwards the response on to the JSP page to actually start, the URL line in the browser has the parameters in it!
If I just use the Web App's login form and only hit the doPost() of the Servlet (and not the doGet()), then I get the desired behavior and do not see the URL parameters.
This is confusing.
I can't understand how to supress the URL parameters. It seems no matter what I do, I'm getting "get" behavior.
I've tried using both response.SendRedirect(<url parameters> and dispather.forward (request, response), but both have this same behavior.
Any ideas would be GREATLY appreciated!!! <s>
Thanks.
-- Mike
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I have a couple of suggestions. Couldn't you pass the request/response object thru the html FORM element. You could set the METHOD attribute to "POST".
Another solution would be to store your information in the ServletRequest scope using the setAtrribute/getAttribute methods.
Craig.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

What the browser shows is the URL that it submitted to the server. Whether you call doPost or forward from that point is completely moot. The method of the request is set by how it is initiated by the browser.
So how are you generating the inital request? If it's a GET, nothing can change it to a post. You need to make sure that your original request uses the POST method.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
Hi Bear,
From Visual FoxPro, I'm calling IE and passing it a URL, like this:
lccmd='run /n7 "C:\Program Files\Internet Explorer\iexplore.exe" ;
http://'+gcWebHost+'/index.jsp'+ ;
'?txtlogin='+STRTRAN(ALLTRIM(USERID),' ','%20')+;
'&txtpassword='+STRTRAN(ALLTRIM(lcPassword),' ','%20')+;
'&fName='+STRTRAN(ALLTRIM(fname),' ','%20')+;
'&lName='+STRTRAN(ALLTRIM(lname),' ','%20') + CHR(13)
---------------
**********************************************
Then, in index.jsp, I do something like this:
**********************************************
RequestDispatcher disp = request.getRequestDispatcher("dispatcher");
.
. (more code to do request.getParameter(...)s)
.
disp.forward(request,response);

}
**********************************************
The dispatcher is a Servlet.
**********************************************
The "forward" above comes into the Servlet's doGet().
I then forward the (request,response) to the Servlet's doPost().
The doPost in the Servlet code finally calls the JSP page that is the Web App. However, when the Web App starts up, using the above methodology, you SEE the passwords and other private stuff inside the Web App.
I need some kind of way of doing a POST without having to manually log in and click SUBMIT.
-------
Does this information help?
Can I get the "hidden URL" doPost() behavior in some way?
Thank you very much for your reply.
I look forward to hearing back.
Thanks much!!!
-- Mike
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Looks like this might be a job for a Filter to me. Your filter for the servlet would substitute your custom HttpServletRequestWrapper which would then be forwarded to the JSP. The custom class would have to return "POST" to the getMethod() call and would probably have to have other modifications.
Seems to me we have had a number of Threads like this recently, why don't you browse around in the recent history.
Bill
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
Hi Bill,
This sounds interesting, but is a bit vague. I'll look around and let you know what I find.
Thanks.
-- Mike
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I will try to elaborate.

First of all you should never send sensitive information i.e. logon, password as part of an url, so everyone can see.
Based on your example:
lccmd='run /n7 "C:\Program Files\Internet Explorer\iexplore.exe" ;
http://'+gcWebHost+'/index.jsp'+ ;
'?txtlogin='+STRTRAN(ALLTRIM(USERID),' ','%20')+;
'&txtpassword='+STRTRAN(ALLTRIM(lcPassword),' ','%20')+;
'&fName='+STRTRAN(ALLTRIM(fname),' ','%20')+;
'&lName='+STRTRAN(ALLTRIM(lname),' ','%20') + CHR(13)

You are using the "GET" method by default. As Bear pointed out, this will follow the request until, I guess it goes out of scope.
Now there are several suggestions to get around this.
1. You can access your servlet thru the html FORM tag, by setting the METHOD attribute to "POST". You can do this by enclosing your code in a jsp page.
2.Storing the information in the ServletRequest object(i.e. setAttribute, getAttribute).
3. Wrapping the request in a HttpServletRequestWrapper object were you provide your own implementation of the getMethod, so as to return "POST" per Mr Brogden.

I hope this helps.
Craig
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

Looks like this might be a job for a Filter to me.

That was my first thought. But I'm not sure that this would prevent the browser from showing the original full URL or not. Not something I've fooled with.
Apparently the FoxPro mechanism doesn't have any means to submit form data rather than a query-stringed URL?
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
Hi guys,
OK, I'm not sure what it means to "access the servlet though the HTML form tag". The problem is that the Visual FoxPro application is starting up IE and passing a GET string to either the JSP page or to the Servlet. POST is already the default in the JSP page, but when I re-direct (forward) it to the Servlet, it still comes across as a "get" (all URL parameters visible). Not sure if this is what you meant.
Can you clarify?
I have no idea how to do number 3 you listed. Yikes!
Does anyone have an example of how to: "Wrapping the request in a HttpServletRequestWrapper object were you provide your own implementation of the getMethod, so as to return "POST" per Mr Brogden."
I appreciate everyone's replies.
Hope to hear back...
-- Mike
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
I can access the servlet from Visual FoxPro using an in-process ActiveX control.
The problem in this case is that IE has not been started so, although I have POSTed the data to the Servlet, there's no Web Application loaded.
Sigh...
-- Mike
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Did you try something along the lines of invoking IE through automation:
This partial example is in javascript (not too familiar with FoxPro syntax)

Based on this reference:
http://msdn.microsoft.com/workshop/browser/webbrowser/reference/methods/navigate.asp
You need to encode "postData" some how for the method to recognise that you are trying to do a post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doGet() calling doPost() problem -- URL line visible in destination page!
 
Similar Threads
Error 400:
Calling servlet from jsp
HTTP method GET is not supported by this URL
ApplicationDispatcher[/WebWormSales] PWC1231: Servlet.service() for servlet jsp threw exception java
to support both get and post methods in one servlet