aspose file tools*
The moose likes Servlets and the fly likes Problem while   posting data from a servlet. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem while   posting data from a servlet." Watch "Problem while   posting data from a servlet." New topic
Author

Problem while posting data from a servlet.

khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17
hi all ,
I created a servlet,from the servlet i posting data to the jsp.
But all the data is public i.e user can be able to see the data in the url.
I tried using post method from the servlet still i can be able to see all the data in the url.
I dont want the user should see the data in the url.
I read something like RequestDispatcher but its not working.
how to solve this.



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

You haven't given us anywhere near enough information. How is the servlet being invoked? What does the getUsernameDetails() method do? And it appears that you are not posting from this servlet, but to it.

Also, a post will not cause the doGet() method to be called.
[ November 21, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17
hi,
Here is the details



the above code will call the servlet and the servlets check the info and respond to displaydata.jsp

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

Sigh. Without knowing what getUsernameDetails() does, I cannot help you.
khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17
hi,
getUsernameDetails will retrieve the datafrom the database

String value=getUsernameDetails(user);

System.out.prinln("value="+value);
//in system.out.println
//value=Valid&designation=Manager&sal=2000
khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17
hi ,
i mean i can see this parameter in the url
value=Valid&designation=Manager&sal=2000

and my query is i dont want to see them in the url

i am not sure this is the soultion or not

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61224
    
  66

Originally posted by khalid ahmed:
getUsernameDetails will retrieve the datafrom the database

String value=getUsernameDetails(user);

System.out.prinln("value="+value);
//in system.out.println
//value=Valid&designation=Manager&sal=2000


If value is coming from the database, what does this have to do with URLs?
khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17
khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17
hi,
The values comes from db and pass to the url like below.

khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17
hi all,
Still i am facing teh problem.
Any help..
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3832

What I can say about what you are trying do is that, can't you set the values in appropriate scope (may be request,session etc..) and let the JSP (in this case) get the values from that scope?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Neha Kathuriaa
Greenhorn

Joined: Sep 16, 2008
Posts: 25
khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17
hi,
I can set the session variable in the servlet and get the variable in a jsp using response.sendredirect method.

like



and in get the varaible


i feel if two customers tried with the same time he may get wrong ouput or there will be some issue with lots of sessions.
I think i clean up the session variable somewhere so that it should not be a problem.am i right or correct if i am wrong somewhere .
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
I am not exactly clear on what you are asking. I do nto see any instance variables in your servlet though, so why do you think there may be a problem with the session if more than one user access your servlet?
[ November 24, 2008: Message edited by: Bosun Bello ]

Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218

Khalid said.
hi ,
i mean i can see this parameter in the url
value=Valid&designation=Manager&sal=2000

and my query is i dont want to see them in the url


Are you sending a redirect to the client?

You initial form posts the data to the server and you wont see the user parameter in the url.
Now when your request reaches the server What is you requirement?
If you send a redirect, then yes the parameters will be visible in the client's browser as you are constructing the url and adding the parameters to the url as query string.
The question is , do you really require a redirect? Cant you use requestDispatcher.forward()? If you use the forward or include (which happens on server side and transperent to end user) you query string will not be visible in the browser.
khalid ahmed
Greenhorn

Joined: Nov 19, 2008
Posts: 17

Amol Nayak says
You initial form posts the data to the server and you wont see the user parameter in the url.
Now when your request reaches the server What is you requirement?



If you send a redirect,
then yes the parameters will be visible in the client's browser as you are constructing the url and adding the parameters to the url as query string.


I solved this query string issue by


get the variable like request.getAttribute("result") in jsp and its working fine.

The problem with the above code is i couldnt be able to invoke the DisplayData.jsp.

i read in internet

The forward is made server-side, meaning the user will still see the first URL he entered.
Also, you keep the same ~Request object when the second URL is loaded, meaning you can share data using attributes.

The redirect is actually a HTTP response sent to the user asking him to go to another URL, meaning that the URL in his address bar will change. The second URL is then a fully new request.


so i tried this code





and in get the varaible





The storing the session variables concept is working.But i feel somewhere session lost or session exists or may be some prob will arise with session so i feel dispatcher.forward method is good to solve the my query.

As i mentioned if i use dispatcher.forward i cant be able to invoke the jsp?No idea how to solve this.
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Khalid said:
As i mentioned if i use dispatcher.forward i cant be able to invoke the jsp?No idea how to solve this.


What exactly is happening?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem while posting data from a servlet.