• Post Reply Bookmark Topic Watch Topic
  • New Topic

java function in jsp  RSS feed

 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have written a small class and want to use it in a jsp page I'm writing. how do I implement that code? Can I place the code directly onto the page? TIA.
kevin
 
Bal Sharma
Ranch Hand
Posts: 273
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are multiple ways. Use scripting <% %>, use your class as java bean, or develop custom tag and use your class. Look at examples how to write simple JSP.
Originally posted by kevin schmidt:
Hi,
I have written a small class and want to use it in a jsp page I'm writing. how do I implement that code? Can I place the code directly onto the page? TIA.
kevin

 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin,
That is what the <%@ import="myclass" %> statement is for. Just import the class this way (like a regular Java import) and then use it within your scriptlets.
Kyle
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
kevin schmidt
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all the help, but the tags that worked for me was the <%! %> tags. Thanks for the direction.
Kevin
 
Adam Hardy
Ranch Hand
Posts: 567
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this thread's exactly what i want to ask as i'm new to java & jsp. i'm working on a production server and don't have a test server (yet) at work and i have no control over the server - i have to go and ask someone to stop and restart it.
if i create a class and want to use it in a jsp, do i have to compile it, place it in a certain directory on the server then restart the web server? i had to do that to use a .jar file i needed.
is there a better way in my situation?
thanks
adam
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can put the class file where ever in the servers directory that you put your servlet class files. ex. for Tomcat, it is WEB-INF/classes. Also, if it's in a package create the corresponding folder under the classes directory, and remember to import the package in your JSP. Yes, you may have to restart some servers after you put the class file there.

Bosun
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!