Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

printing a java variable in jsp form

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All
I have a small code in JSP as following :

<%@ page language='java'%>
<%@ page import='java.*'%>

<%
Java_module obj = new Java_module();
%>
<body bgcolor="lightblue">
<form name="form1">
<input type="text" name="text1" size="100">
<input type="submit" name="enter" value="Click" onlick="return(callme())">
</form>
</body>
<script language="javascript">
function callme()
{
<% String s_result=obj.disp();%>
document.form.text1.value= <%= s_result%>
return false;
}
</script>

and the Java_module is as follows

public class Java_module
{
public String disp()
{
String str="JAVARANCH";
return str;
}
}


In general what would be the way to retrieve a string from a java method and display it in a textbox of a form in a JSP file
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

if varaiable name in java is temp and if you want to assign this value to text box then this is the way

<input type="text" name="text1" size="100" value="<%=temp %>">

With regards
pankaj
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you explore using the JSP Expression Language together with JSTL.

For example, ${temp} will result in a search for the variable, in this case temp, within the page, request, session and application scopes. Much nicer than using scriptlets and JSP expressions.

In this way you can eventually get rid of all the inline Java from your JSP.
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
put ; for this line
document.form.text1.value= <%= s_result%> ;
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic