• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

call Java class from JSP

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am new to JSP. Was trying to do a very basic JSP coding.
I have a Helloworld.java which displays "hello world!".
Now I want to have a jsp page called hello.jsp which displays "hello world!". i.e I was trying to call my Helloworld.class from hello.jsp. Can anyone tell me how to do that.
Thanks
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bubly,
What does your class do with the "Hello World" text? If the class prints it to the screen, calling it in a JSP would write the text to the console. If the class, returns it as a String, you can output it in the JSP.
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All you have to do is make your java class a bean, which is very simple. You just make sure you have an "accessor" method to the property you want displayed that returns a String. In this case, the property you want displayed is the String, "Hello World" (I'm guessing). Write a method getMessage() or getString() or some other such "get" method that returns the String. Then in the JSP you must use the <jsp:useBean /> and <jsp:getProperty /> tags. You can also use the JSP 2.0 Expression Language instead of the getProperty tag. For more information on these tags, custom tags and the expression language, try Sun's tutorial or book on JSP. I really liked "Web Development with JavaServer Pages" by Duane Fields and Mark Kolb, but it's out of date at this point as it does not cover JSP 2.0. I'm looking at Pro JSP, 3rd edition from apress! right now and it looks pretty good.
 
Sheriff
Posts: 67746
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
"Bubly KK",

We're pleased to have you here with us on the Ranch, but there are a few rules that need to be followed, and one is that proper names are required. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
Forum Bartender
 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Thanks for your replies. I really appreciate.
Thanks
 
Bear Bibeault
Sheriff
Posts: 67746
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
"Bubly K", I hate to be a pest but your display name is still in violation of the JavaRanch naming convention, Your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Please be aware that accounts with invalid names are subject to closure.
 
reply
    Bookmark Topic Watch Topic
  • New Topic