File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "passing parameters to servlets " Watch "passing parameters to servlets " New topic

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>
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();
PrintStream pt = new PrintStream(urlcon.getOutputStream());
str += " got printstream";
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 ,
Frank Carver

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 ~ 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 ???
I agree. Here's the link:
subject: passing parameters to servlets
jQuery in Action, 3rd edition