www.webdeveloper.com
Results 1 to 4 of 4

Thread: Pass a value to java class

  1. #1
    Join Date
    Feb 2005
    Location
    India
    Posts
    2

    Pass a value to java class

    I just want to pass a value to java code.
    I had assgined a value to the variable which I am going to pass.
    Please help me?
    Thank in advance.
    Krishnakumar M

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    PHP Code:
    wrong forum(may be?).
    If 
    you are trying to pass a value to a Java Servlet then its very easy to pass parameters to the Servlet.
    Just append the value to the URL and then submit a request.
    Suppose you have a servlet name GetUserInfo.class on tomcat at the following url
    [url]http://localhost:8080/servlets/GetUserInfo[/url]
    Then what you will need to do is add user name and password to the url above in the name and value pairs
    suppose user name is 
    khalid
    and password is =password
    then 
    if you want to send this info from a link to the servlet it will look like this

    <a href="http://localhost:8080/servlets/GetUserInfo?name=khalid&password=password"

    and when you click on the above above info will go to the servlet where you can retrieve it as follows

    String userName 
    request.getParameter("name");
    String password request.getParameter("password");

    in the above code you must always make sure that there is never a null value before you use it.
    if(
    null==userName){
    //some error capturing here
    }else if(null==passowrd){
    //another error capturing
    }else{ all is well so go in prcess
    //validate from databate
    }

    if 
    the above info is in a form then you don't need to append it to url just make sure the action attribute of your form points to the servlet.

    I hope this helps, you should post any Java related questions in Java forums... 
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Feb 2005
    Location
    India
    Posts
    2

    I need to pass a value from javascript

    Hi ,
    I just want the value to be passed from the Javascript to Java code?
    Sorry for incomplete data.
    Thankx,
    Krishnakumar M

  4. #4
    Join Date
    May 2003
    Location
    O!
    Posts
    200
    You have to call methods in the Java code to pass/retrieve data. It is no different that passing values to a JavaScript function.

    Here are some snippets from one of my web pages that should demonstrate passing data. There are 2 Java applets in the page, one (jclient) to get data from a C server using an socket connection and one (LineChartApplet) to display the data in a line chart.
    Code:
    <applet code="jclient.class" archive="./Includes/jclient.jar" name="dataaccess"></applet>
    <applet code="com.objectplanet.chart.LineChartApplet" archive="./Includes/chart.jar" name="linechart"></applet>
    
        function buildselLocale()
         {
          // build the device/station select list
          var cnt = document.dataaccess.getlocCnt();
    
          for (var i = 0; i < cnt; i++)
              {
               document.frmMain.selLocale.options[i] = new Option(document.dataaccess.getjobDesc(i));
               document.frmMain.selLocale.options[i].value = document.dataaccess.getjobID(i);
              }
    
         } // end of buildselLocale
    
        function drawchart(cnt)
         {
          document.linechart.setParameter("range", document.dataaccess.getMaxYAxis());
          document.linechart.setParameter("seriesCount", document.dataaccess.getSeriesCnt());
          document.linechart.setParameter("seriesLabels", document.dataaccess.getSeriesLbls());
          document.linechart.setParameter("sampleColors", document.dataaccess.getColorSet());
          document.linechart.setParameter("sampleCount", document.dataaccess.getSampleCnt());
          document.linechart.setParameter("sampleLabels", document.dataaccess.getSampleLbls());
          document.linechart.setParameter("gridLines", document.dataaccess.getGridSet());
          for (var i = 0; i < cnt; i++)
              {
               document.linechart.setParameter("sampleValues_" + String(i),
                                               document.dataaccess.getSeriesData(i));
              }
          document.linechart.setParameter("title", "Average Ping Times For " +
                   document.frmMain.jobid.value + " On " + document.frmMain.jobdate.value);
          setTimeout("document.linechart.chart.forceRepaint();", 500);
    
         } // end of drawChart
    function buildselLocale() passes an index value (i) to method getjobDesc in applet jclient which, in turn, returns the job description(s) that are used to build the select list selLocale.

    In function drawchart(), calls to method setParameter in applet LineChartApplet pass a string that designates the parameter to be set along with the value. The value passed to method setParameter is the value returned from one of the many data retrieval methods in jclient.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles