This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to configure tomcat for a subdirectory of jsp files

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a standard java web application package under public_html. My java source code is under WEB-INF/classes/. My jsp files are under public_html and public_html/version/v1. Now all of my jsp file under public_html is running fine, however, the jsp files under public_html/version/v1 do not work with following error:

HTTP Status 500: Unable to compile for class JSP:
type Exception report
message Unable to compile class for JSP:
description The server encountered an internal error that prevented it from fulfilling this request.
exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 8 in the jsp file: /index.jsp
Utility cannot be resolved to a type


Utility is one of my java file under WEB-INF/classes.

It looks like there is a problem with tomcat configuration of either server.xml or web.xml. Can anybody help me to make the jsp files under public_html/version/v1/index.jsp work?

Thanks,
 
Bartender
Posts: 20924
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I understand.

Did you create public_html under the TOMCAT_HOME/webapps directory or somewhere else?

Also, Java source code is not located under /WEB-INF/classes. Actual Java source should not be included in the WAR - it's an unneccesary security risk. JSP source cannot be located under /WEB-INF at all, because no resource under /WEB-INF can be accessed by a remote user via a URL request.

I'm assuming that public_html/version/v1 is supposed to be an alternate version, but I haven't been using Tomcat's versioning option myself, so I don't know what the restrictions are.
 
Xiaotian He
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The folder public_html is standard setup under TOMCAT_HOME for Linux. And the WEB-INF/classes is, too. I am using commercial product CPanel, in which all setup is standard.
 
Tim Holloway
Bartender
Posts: 20924
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry. There has never been a "public_html" directory under standard Tomcat. Actually, "public_html" is more likely to be a sometimes-standard directory for the Apache httpd webserver, which is a completely different product (and which cannot directly serve JSPs).

I'm afraid that cpanel is obscuring your Tomcat configuration in an attempt to make it "zero knowledge", and in the process, it's making it impossible for me to tell what's actually going on. Since cpanel is a commercial product, I recommend that you contact their technical support. I don't have a cpanel license so I cannot tell what it's doing.
 
Xiaotian He
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody else knows how to handle it?
 
Xiaotian He
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim,

In your case under TOMCAT_HOME/webapps, how do you handle a subdirectory of JSP files? how do you configure tomcat?
 
Tim Holloway
Bartender
Posts: 20924
127
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I normally don't use "control panel" apps to configure Tomcat myself, so I'm manually doing what those apps would do for me.

Every J2EE/JEE web application must be in the form of a WAR or EAR. Tomcat doesn't handle EAR format, so all Tomcat webapps must be in WAR form. The WAR (Web Archive) format is an extended form of the Java JAR file format, which in turn, is an extended form of ZIP file format. The standards-mandated WAR is a single file with a specific set of resources in it. Tomcat, like many other webapp servers also allows what's known as an "exploded WAR", which is simply a directory whose contents are the unzipped WAR file.

No matter how you deploy your webapps, regardless of whether it's via a master-control webapp like cPanel, the Tomcat Manager/Admin webapps, the J2EE deployment API, or, like me, by brute-force file copying, the webapp must be in WAR format.

Traditionally, a WAR always had a WEB-INF/web.xml file to configure it. In recent JEE specs, the web.xml file is optional, since newer webapp servers can scan class annotations and synthesize a web.xml, but the basic architecture remains.

Within a WAR, you can place JSPs anywhere, but if you place them under the WEB-INF directory, they cannot be accessed by clients via URLs. Otherwise, the convention is that the URL for a JSP within a WAR is mapped to the war's directory pathname of the JSP file.

So, if I create a WAR named "mywebapp", and deploy it using Tomcat's default deployment/configuration services, the JSP I've defined in the WAR at "/forums/messageEdit.jsp" would have a corresponding URL of "http://mytomcat:8080/mywebapp/forums/messageEdit.jsp".

If you interact with Tomcat deployments at the file level, you'll find that Tomcat has a "TOMCAT_HOME/webapps" directory. This is where WARs are located by default. The webapp's URL context path (for example, "/mywebapp") defaults to the name of the WAR. If I copy in a "mywebapp.war" file to TOMCAT_HOME/webapps, then Tomcat will detect it, unzip it to create a corresponding TOMCAT_HOME/webapps/mywebapp directory, and use that as the resource base (codeBase) of "mywebapp". Note that once Tomcat has created an exploded WAR, it will ignore any war file of the same name, even if you update or replace that WAR file. So to deploy a new version of the webapp, the exploded WAR has to be replaced or deleted.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!