Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display sum of numbers from a java class to a jsp using custom tag?

 
ashley Jug
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i have a jsp page that takes 2 numbers.A servlet that initialiase the two number based on data sent from the jsp as follows:


Then the servlet call a method as follows to add the two numbers:


My question is, is it possible to display the total variable in a jsp using a custom tag?
If it is possible how do i initialise the custom tag to take the variable total?

Thanks a lot.





 
Paul Clapham
Sheriff
Posts: 21140
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess it might be, given a suitable interpretation of your question. For example: what does it mean to you to "display a variable in a JSP"? I'm finding your terminology a bit hard to follow.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64976
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do need a custom tag? Just have the servlet set the value as a scoped variable and use the EL to display it. Why make things one iota more complicated than they need to be?
 
ashley Jug
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

thanks a lot its all new to me, i will use scope variable and jstl.

Do you know any online resources where i can get turorial of using scoped variable with jstl please?

Thanks again.
 
Piyush Joshi
Ranch Hand
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Execuse me for diverting from the topic. But there is a bug in your code:
ashley Jug wrote:

If num1 or num2 were null then how you will be able to call equals() on them, causing NullPointerException!
Please correct this

 
ashley Jug
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Thanks to point out the null pointer check...but i am using jstl now to display the variable total but no data is displayed.
My jsp file to display the total is :


My jsp file to input the numbers is as follows:


My servlet MathUtilsController is as follows:


Java class is as follows:


Not sure what i am missing here.

Any suggestion please why the variable total is not displayed?

thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64976
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


and



do not match.

Why the extraneous prefix?

(Also, use lowercase for HTML -- all uppercase looks so 1998.)
 
ashley Jug
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

opps sorry for the prefix i know its not being used. Thanks a lot now its being displayed.

Quick question:

I was going through an on line tutorial to display the data on a jsp they use:

<td>${Classname.variable}</td>

For instance:

<td>${MathUtilsController.total}</td>

When do we use the above format to display data in a jsp?

For the html you mean use lowercase to define the html tag?

Thanks again learning a lot from this forum.
Thanks again.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64976
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${xyz.abc} when abc is a property of bean abc.

I mean <td> and not <TD>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic