Hi everybody,

 i have a requirement to pass the value of a javascript
 variable to a servlet. i have the following javascript
 function in a html page.

 <html>
 <head>
 <SCRIPT LANGUAGE = "Javascript">
 function javascriptFunction ( ) {
 y="html page";
 }

 </SCRIPT>
 </head>

 i want this function to be executed as soon as the html
 page is viewed. hence i have put the following in the html :

 <BODY onLoad = "javascriptFunction ( ) ">

 after the above function has been executed, i want a servlet to be
 executed at the server and i want to pass the value contained in the
 variable y of the javascript function to the servlet. and i want the
 servlet to be executed automatically without any user intervention. the

 servlet gets executed at the server end, but i am unable to pass the
 value of the variable y in the javascript function. is this code in the

 html page to pass the parameter ok ?

 <img src =
 "http://202.201.134.78:8080/servlet/image?b="+javascript:javascriptFunction(
).y
 width = 1 height = 1>

 i am doing nothing in the servlet except String strTemp =
 req.getParameter ("b") and then writing back an 1 x 1 image.
 strTemp
 just prints blanks. following is the servlet code.



 import java.io.*;
 import java.util.*;

 import javax.servlet.*;
 import javax.servlet.http.*;

 public class ImageServlet extends HttpServlet {

 public void doGet (HttpServletRequest req, HttpServletResponse res)
 throws ServletException, IOException {

 String strTemp = req.getParameter ("b");
 System.out.println ("parameter b : " + strTemp );

 res.setContentType ("image/gif");
 res.setHeader( "Pragma", "no-cache" );
 res.setHeader( "Cache-Control","no-cache" );
 res.setHeader( "Cache-Control","no-store" );
 res.setDateHeader( "Expires", 0 );
 FileInputStream bTemp = new FileInputStream
 ("c:/javeed/servlets/images/temp.gif");
 int iLength = bTemp.available ();
 byte[] byteArray = new byte [iLength];
 for (int b=0; b< iLength; b++) {

 byteArray [b] = (byte) bTemp.read ();
 }
 bTemp.close ();
 ServletOutputStream out = res.getOutputStream ();
 out.write (byteArray);
 out.flush ();
 out.close();

 }

 }

 Thanks and Regards,

 Javed

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to