• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying Variable in JSP! Urgent please

 
Kris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can Somebody help me to display varaible from JSP.
For Example String a ="Hello World". I want this message to be displayed from JSP.
Thanks in advance.
Kris
 
Edgar Sanchez
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, is this variable defined in the JSP itself, in a servlet, in a business class (and in this case as an attribute to the class or as a local variable). Give me some extra info and I'll try and help.
Best luck,
Originally posted by Kris:
Can Somebody help me to display varaible from JSP.
For Example String a ="Hello World". I want this message to be displayed from JSP.
Thanks in advance.
Kris

 
Kris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This variable is declared and defined in JSP.
For example
int a = 10 + 20;
I want to display the value 30 from JSP to Browser.
From Class I could get the value of function.
Thanks for your help.
Help me further more.
Thanks
kris
 
Cynthia Yao
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if u declare the variable like this:
<% int i=20;
%>
then u can either use
<%=i%>
or
<%pageContext.getOut().println(i);
%>

 
Kris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Cynthia it works. I have one more question. When call funtion from class with the help of "set" and "get" property,it works well. But if I want to use like a function in my class as
"addNum" which returns integer value. How Do I get this function in JSP by assigning to a variable and display it in JSP itself.
For Example <% int a = HW.addNum() %> is not working.
Hope I am clear.
Please any body help me.
Thanks
Kris
 
Kris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reply Please!
Tks
kris
 
maheshe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If u need to call a method in a Jsp.
First u should declare/define that method with
this tag
<%! public int add(int a,int b)
{
return(a+b);
}
%>

<% // Calling method
int sum = add(3,3);
%>
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'kris' and 'maheshe'

Your name does not comply with the JavaRanch naming policy. Please choose one that meets the requirements.
Javaranch appreciates your cooperation to comply with the official naming policy.
Ajith
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic