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
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
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...
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.
Bookmarks