Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSPs and package statements

 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all!
Is there any way to put a package statement in a JSP as in a regular Java class?

If so, is there any reason to do this?
 
Michael Zalewski
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it makes sense to do this. Your application server will map each .jsp to a specific servlet. If you changed the package, you would change the location of the .class file for this servlet, so the application server would probably not be able to find the servlet class.
But you can do this:

Then you could have


But, this procedure will likely tie you down to your particular JSP page compiler.
But instead of doing this, I would be tempted to do the following: Get rid of all scriptlets in your JSP pages, and replace them with TagLibs. You can then put the .java source into any package you want.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic