Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem while posting data from a servlet.

 
khalid ahmed
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
khalid ahmed
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sigh. Without knowing what getUsernameDetails() does, I cannot help you.
 
khalid ahmed
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
khalid ahmed
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
The values comes from db and pass to the url like below.

 
khalid ahmed
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
Still i am facing teh problem.
Any help..
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Neha Kathuriaa
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
khalid ahmed
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Amol Nayak
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic