Tomcat6 exception: only a type can be imported Solution

Source: Internet
Author: User

In this project development, the tomcat version of the runtime environment has been upgraded from 5.5.12 to 6.0.18. If you find that the previous project cannot run, an error will be reported when you access a very simple JSP, saying that compilation is not possible, the error is: only a type can be imported. com. xxx. xxx. xxx resolves to a package, which means that the class referenced on your JSP page does not exist, but it runs well in the old version, in addition, the JSP access under the root directory of the Project is normal, and an error is reported under the subdirectory. After Google, it is found that this is a change in the new version of Tomcat, that is, if context is not specified, every sub-folder will be Tomcat as an independent virtual application, so the JSP page under each sub-folder access, will find the class in the WEB-INF in its same layer, of course, this cannot be found. It can only be accessed by JSP files in the root directory.

Solution: In fact, this was caused by nonstandard writing when I wrote the tomcat configuration file. The host information code in the previous server. xml file is as follows:

<Host name = "www.local.com" appbase = "D: // projects // mywebsite // webcontent "unpackwars =" true "autodeploy =" true "xmlvalidation =" false "xmlnamespaceaware =" false ">
<Alias> 192.168.1.43 </alias>
<Context Path = "" docbase = "" reloadable = "true">
<Logger classname = "org. apache. catalina. logger. filelogger "directory =" logs "prefix =" www.local.com _ log. "suffix = ". TXT "timestamp =" true "/>
</Context>

In this case, the docbase In the context is empty, and the file path is specified by the appbase in the host, so Tomcat considers that there is no application in your site, each folder is automatically processed as a virtual application. The modified code snippet is as follows:

<Host name = "www.local.com" appbase = "" unpackwars = "true" autodeploy = "true" xmlvalidation = "false" xmlnamespaceaware = "false">
<Alias> 192.168.1.43 </alias>
<Context Path = "" docbase = "D: // projects // mywebsite // webcontent" reloadable = "true">
<Logger classname = "org. apache. catalina. logger. filelogger "directory =" logs "prefix =" www.local.com _ log. "suffix = ". TXT "timestamp =" true "/>
</Context>

We can see that the appbase is no longer specified in the host, but an application is created under the host. The file path of the application is specified through docbase, so that the class cannot be found.

PS: the problem of Tomcat seems to have started from 5.5.28. I remember that a similar problem occurred when I tried to upgrade Tomcat before, but there was no time to solve it, the problem persists until now.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.