• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.





 
Sheriff
Posts: 28371
99
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 207
jQuery Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
${xyz.abc} when abc is a property of bean abc.

I mean <td> and not <TD>
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic