Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

printing a java variable in jsp form  RSS feed

 
gk anand
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
 
pankaj patil
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • 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
 
Keith Pitty
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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.
 
vidhyasagar reddy
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put ; for this line
document.form.text1.value= <%= s_result%> ;
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!