Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes passing parameters to servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing parameters to servlets " Watch "passing parameters to servlets " New topic
Author

passing parameters to servlets

ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111
how can we pass parameter from applet to servlet , I mean in
<applet code=applet.class height=30 width=30>
<param name=adclient value=sun>
</param>
</applet>
in my applet.class i can retrive parameter adclient value using
getParameter("adclient") , then in my applet i am opening urlconnection to servlet like this
URL upurl = new URL("http://comp7:8080/servlet/DisplayerServlet");
URLConnection urlcon = upurl.openConnection();
urlcon.setUseCaches(false);
urlcon.setDoOutput(true);
PrintStream pt = new PrintStream(urlcon.getOutputStream());
str += " got printstream";
pt.print(str);
pt.flush();
urlcon.getInputStream();
now I can retrive every string in servlet that is passed by applet using printstream.print(string) , but how can i get parameter "adclient" value of applet in servlet ,
thanks
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
If you add the parameter to your URL string it will be available as a parameter in the servlet request. For example:
URL upurl = new URL("http://comp7:8080/servlet/DisplayerServlet?adclient=hello");


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111
thanks for your reply , I have done this also
"http://comp7:8080/servlet/DisplayerServlet?adclient=hello" but then applet can not establish connection to url and it throws exception , is there any other way to do this , I also tried to encode the url but then applet throws not protocol exception and can not establish connection with servlet , same with
"http://comp7:8080/servlet/DisplayerServlet?adclient=hello" ,applet can not establish connection to servlet and throws exception , how can i pass parameter to servlet ???
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing parameters to servlets
 
Similar Threads
mapping all jsps to single servlets init parameters
Using servlets params from filters
request.getParam...
applet to servlet
Passing web.xml info to servlets