TomExam_v2.1_UTF8访问jsp时报错:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 8 in the generated java file
Only a type can be imported. com.tom.cache.ConfigCache resolves to a package
发现WEB-INF\classes下并没有类而是打tomexam.jar包放在了WEB-INF\lib下
解决办法:
在%CATALINA_HOME%\conf\server.xml的虚拟主机中通过Context子元素指定其Root Context所在位置:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <Context path="/TomExam_v2.1_UTF8" docBase="D:\dev_tools\apache-tomcat-6.0.32\webapps\TomExam_v2.1_UTF8\WebRoot" reloadable="true" /> </Host>
只要加多个context就可以了,其中path为访问路径,docBase为项目文件根目录所在。这样应用的文件路径通过docBase来指定,这样就能在WEB-INF的lib载到包找到类了。