• Post Reply Bookmark Topic Watch Topic
  • New Topic

call Java class from JSP

 
Subha Rangu
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35744
412
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
M. Gagnon
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi all,
Thanks for your replies. I really appreciate.
Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!