• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

packages

 
Kris Reid
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way for a JSP to access a class not in a package?

I just completed the DiceRoller app on page 390 of HFJS
I didn't put the DiceRoller class in a package and it didn't work.
but as soon as I add it to a package and changed the TLD it works fine.

Why can't a JSP find a class that is not in a package?
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No its necessary that the servlet class has to be in package
Just make sure it is under classes directory of WEB-INF
Also in the JSP make sure you give the servlet mapping name without starting with /

for eg in JSP you give action="NewServlet" not "/NewServlet"
where NewServlet is the servlet mapping specified in the DD
 
Saulius Sinkunas
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I remember, you can't normaly use class for web appication, which is in defualt package (i.e. is not in any package). So all classes used in web app must be in packages.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I too doubt if you can use classes in a JSP that are not there in a package. I read somewhere that the JSP Container expects all classes to be in a package. So this might work in some Application Servers and in some it may not.
In practical applications, all classes are defined in a package anyway.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic