This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes I want to make static URL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "I want to make static URL" Watch "I want to make static URL" New topic
Author

I want to make static URL

Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Hello,

My servlet URL is changing options and URL is like:

doGet method is used to retriew the relevant data.

Question:
=========
I want that URL should not be changed like doPost method and URL should remain as it is when it was displayed first time

Thanks in anticipation

Best regards

Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

You can have a hidden field on form and have the value as per the requirement.
This hidden value will be passed to servlet as a part of header and will not b shown in url if you will use the post method
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Harpreet Singh janda wrote:You can have a hidden field on form and have the value as per the requirement.
This hidden value will be passed to servlet as a part of header and will not b shown in url if you will use the post method


You are right but I am accessing directly the URL through doGet method as doPost is not supporting direct access from URL

Is there anyway else around?

Best regards
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

If you want the servlet to respond to POST requests, then it has to have a doPost() method. Parameters in a GET request are included in the query string portion of the URL. Parameters in a POST request are included in the body of the request and do not appear in the URL.


SCJP 6 || SCWCD 5
Farakh khan
Ranch Hand

Joined: Mar 22, 2008
Posts: 732
Michael Angstadt wrote:If you want the servlet to respond to POST requests, then it has to have a doPost() method. Parameters in a GET request are included in the query string portion of the URL. Parameters in a POST request are included in the body of the request and do not appear in the URL.


I didn't want to use POST requests but looking for the way if possible to hide the URL.

best regards
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Farakh khan wrote:I didn't want to use POST requests but looking for the way if possible to hide the URL.


Where are you accessing these URLs from? A form? A link? Can you provide an example of how you are using these URLs?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

And why do you want to hide the URL?
Sean Clark
Rancher

Joined: Jul 15, 2009
Posts: 377

Hey,

I think there might be a few ways you could get around this, you could use javascript to make an AJAX request to get the data so that the page doesn't change. You could also send a redirect back to the plain url and stored something in the session that the servlet picks up.

I wouldn't use either of these though, why are you not just using a POST?

Sean


I love this place!
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Sean Clark wrote:Hey,

I think there might be a few ways you could get around this, you could use javascript to make an AJAX request to get the data so that the page doesn't change. You could also send a redirect back to the plain url and stored something in the session that the servlet picks up.

I wouldn't use either of these though, why are you not just using a POST?

Sean
Indeed, AJAX it's a good call.

You could also just use one Servet in your app and set the diference by a hidden attribute.

Let's say, for login jsp you could use "userLoing" then to list something "somethingList". By doing this, you will always remain with the same URL.


[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Sean Clark wrote:...why are you not just using a POST?

It's true that using the POST method would prevent the request parameters from appearing in the URL. But we don't know why Farakh wants to do that. Using the POST method might not solve the actual problem; I don't consider showing request parameters in the URL to be a problem, but Farakh does. Again, we don't know why.
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Paul Clapham wrote:I don't consider showing request parameters in the URL to be a problem, but Farakh does.


I can think of one reason why using GET can be a security risk: A login form that uses GET would put the username and password in the URL. Even if the connection is secure (https), this makes the password visible to anyone who is standing over the user's shoulder (does https encrypt the URL too? If not, then the information is visible to packet sniffers too). Also, because the browser's history saves every URL the user visits, the user's login information will be saved there, allowing anyone who has access to that computer to get this information.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Michael Angstadt wrote:
Paul Clapham wrote:I don't consider showing request parameters in the URL to be a problem, but Farakh does.


I can think of one reason why using GET can be a security risk: A login form that uses GET would put the username and password in the URL...


Yes, that's certainly true. You definitely want to use POST there, and https as well. But it doesn't resemble Farakh's initial post though. I'm waiting for a description of the real problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I want to make static URL