This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Tomcat and the fly likes How to preload a JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to preload a JSP?" Watch "How to preload a JSP?" New topic
Author

How to preload a JSP?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Did a search and couldn't find anything that seemed straightforward to preload a JSP when server starts...

Was thinking about creating a servlet called JspStarter to preload the JSP as it's easy enough to call a servlet at server startup - or is there a simpler way?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

You were searching with the wrong keywords.
I think the term you're looking for is 'precompiling' or 'pre-compiling'.
fficial&client=firefox-a" target="_blank" rel="nofollow">http://www.google.com/search?q=precompiling+jsps&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-USfficial&client=firefox-a


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
paritosh ranjan
Ranch Hand

Joined: Aug 24, 2007
Posts: 62
i think you will have to pass the parameter jsp_precompile=true for precompiling that jsp without executing it along with the URL
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by paritosh ranjan:
i think you will have to pass the parameter jsp_precompile=true for precompiling that jsp without executing it along with the URL


Precompilation of JSPs is not spec driven, so, if you are going to recommend settings, it would be good if you would also tell us exactly what container and version you are using.
paritosh ranjan
Ranch Hand

Joined: Aug 24, 2007
Posts: 62
I am using apache-tomcat-5.5.23
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Pass the pre_compile parameter were?
What file is this in?
paritosh ranjan
Ranch Hand

Joined: Aug 24, 2007
Posts: 62
http://localhost:8080/chapter11/implicit.jsp?jsp_precompile=true
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60766
    
  65

Your URL, pointing to localhost, is useless to anyone but you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
He was demonstrating how to use the precompile parameter.

It didn't quite hit the nail on the head anyway. The solution I've found was to add to WEB-INF/web.xml file:

<servlet>
<servlet-name>login</servlet-name>
<jsp-file>/login.jsp</jsp-file>
<load-on-startup>1</load-on-startup>
</servlet>

Haven't tried it yet. Will be back if it doesn't work...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

My point to paritosh is that this is not spec driven, and thus different for every container. Because of this, it makes no sense to start giving directions for one container before finding out from the original poster, which they're using.

Since everyone here seems to be talking about Tomcat, I'm going to move this to our Apache / Tomcat forum.
paritosh ranjan
Ranch Hand

Joined: Aug 24, 2007
Posts: 62
Ben

As you said
"I think the term you're looking for is 'precompiling' or 'pre-compiling'."

So I just tried to help in pre compiling the jsp.

I didn't knew that it was container specific.
This is one thing that I learned from this discussion.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by paritosh ranjan:
Ben

As you said
"I think the term you're looking for is 'precompiling' or 'pre-compiling'."

So I just tried to help in pre compiling the jsp.

I didn't knew that it was container specific.
This is one thing that I learned from this discussion.


It would be nice if there was a simple, spec driven way to force pre-compilation of all JSPs (without having to map them all in web.xml) when the container starts up but, alas, there isn't.

Thanks for your help.
H. Hall
Greenhorn

Joined: Sep 14, 2007
Posts: 8
How about using the jspc utility (jsp compile)?

This is a script provided by Tomcat for precompiling jsps. To execute, supply the name of the JSP you wish to compile, e.g:

# $CATALINA_HOME/bin/jspc.sh $CATALINA_HOME/webapps/myFile.jsp

An equivalent .bat file is provided for Windows users.

Use a script or Ant to compile all jsps in a directory.

By the way, Tomcat 6 provides the ability to serve up the old version of a jsp until it compiles the new version.

You may want to read this:
Apache Tomcat 6.0 Jasper 2 JSP Engine How To

Scroll down to "Web Application Compilation"

Cheers
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to preload a JSP?
 
Similar Threads
Preloaded servlet
Servlet failed to preload on startup in Web application
preloaded servlets
Cannot Preload Servlet - How to
when init() method is called ?