Reputation: 5116
I have a scenario in which there is a jsp, which has couple of hyperlinks. One of the link is coded this way.
<a href="Example?op=srk>hyperlink 1</a>
<!--The value srk is replaced dynamically in code-->
The above link, would send the request to the servlet named Example
passing the request parameter through the url. As it's a hyperlink, the request is sent to the Example
Servlet's doGet() method. In that I am utilizing the request param, processing something and forwarding the request to another jsp further, attaching an attribute(with some object in it) for that request. Functionality works, and I got what I need. But, the side effect or the problem I feel is the URL in the browser has the request parameters visible as shown below.
http://localhost:8080/context/Example?op=srk
I don't wish to see the parms which are being sent. Firstly, Is my approach reasonable? I mean, Is there any better alternative way to achieve this. I am using the core J2EE(JSP and Servlets), no frameworks, no JavaScript as of now.
Upvotes: 1
Views: 119
Reputation: 8187
I elaborating @Sezin's answer , the best way is to go with the POST
method to avoid your parameters visible in the url.
As you said your are populating the dynamic value in the op=srk
variable . you can use a html form to store the variable op
in the form as hidden variable .
you can use the submit
button in the form , so that you could handle the request in the doPost()
of your servlet .
Hope this helps !!
Upvotes: 1
Reputation: 2525
As you click on this link, you're doing an HTTP GET request to your servlet which's why you see the parameters you're passing. You can consider yo use a form or an alternative so you can do an HTTP POST request. After that implementation, this will not be on the address bar.
Upvotes: 0