/servlet URL mapping in tomcat

Source: Internet
Author: User
Tags new features tomcat
Servlet I always thought the latest version was the most functional, so I used the tomcat5.0.19, but as per the book I make up each servlet, debugging in the project directory in the Web-inf/web.xml add code similar to the following:



<servlet>

<servlet-name>counterservlet </servlet-name>

<servlet-class>mypack. Counterservlet </servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>counterservlet </servlet-name>

<url-pattern>/counter</url-pattern>

</servlet-mapping>



Later, after many inquiries, it became known that Tomcat had a caller (Invoker servlet), as long as the following code was added to the web.xml:

<servlet-mapping>

<servlet-name>invoker</servlet-name>

<url-pattern>/servlet/*</url-pattern>

</servlet-mapping>



Directly with http://localhost:8080/project directory name/servlet/servlet name of the way directly debugging, if the project is root, the project directory can be province or Http://localhost:8080/servelt/servlet name. But I use the above method in TOMCAT5 is always unsuccessful (all other configurations are correct), and start Tomcat's DOS window appears multiple lines "serious" words, Hint wrong on the web.xml, even basic Tomcat default page error, the above servlet-mapping removed, there is no more problems. Then carefully looked at the online posts, found that the Internet to talk about the caller's NPC is TOMCAT4, but also heard that tomcat5 relative to Tomcat4 is some changes, so from the official online tomcat4.1.30 version, and then try the above method, incredibly became. Naturally my on the machine also completely switch to TOMCAT4. Because I have WIN2K+WINXP dual system, in order to understand the new features of TOMCAT5, in another system also equipped with TOMCAT5, but debugging or use of TOMCAT4, this question also put down.



It was only yesterday that the caller was enabled by default, due to the revelation of a security flaw, so that later versions of the tomcat4.1.12 are disabled by default. If you want to enable it, you need to uncomment the servlet-mapping in the Conf/web.xml file without the element below. Open the corresponding web.xml and find that there really are



<!--the mapping for the invoker servlet-->

<!-

<servlet-mapping>

<servlet-name>invoker</servlet-name>

<url-pattern>/servlet/*</url-pattern>

</servlet-mapping>



-->



Just added an annotation character, disabled. To lift the ban, there is no need to add, only use the annotation to remove the line (then I did not pay attention to it, hehe.) Take for granted, I looked at the corresponding tomcat5 of the web.xml, it also has these items, is added to the note, the phase must have this function! Then switch the system, run, or the above error. Oh, yes, in the Web.xml configuration, pay attention to, the corresponding relationship, in time to view the TOMCAT4 and TOMCAT5 respectively, really found



<servlet>

<servlet-name>invoker</servlet-name>

<servlet-class>

Org.apache.catalina.servlets.InvokerServlet

</servlet-class>

<init-param>

<param-name>debug</param-name>

<param-value>0</param-value>

</init-param>

<load-on-startup>2</load-on-startup>

</servlet>



The difference is that in TOMCAT5, the above code adds an annotation character that is disabled, and TOMCAT4 does not, which explains why TOMCAT5 is always wrong. So immediately remove the annotation symbol, and then try Tomcat5, initialization did not appear "serious" words, the operation is no problem, another question solved.

In summary, in TOMCAT4, the servlet caller is enabled, only the annotation character named Invoker is removed, and in Tomcat5, you also remove the annotation character with the same name.





Additional: Tomcat4 Highest edition 4.1.30, TOMCAT5 newest edition 5.0.27 can download at Tomcat official address

http://http://jakarta.apache.org/site/binindex.cgi Download

==================================================

Looking at the release-note of Tomcat (my version: 5.0.25), you'll find the following paragraph:

------------------------
Enabling Invoker servlet:
------------------------

Starting with Tomcat 4.1.12, the invoker servlet are no longer available by
Default in all WebApps. Enabling it for all webapps are possible by editing
$CATALINA _home/conf/web.xml to uncomment the "/servlet/*" servlet-mapping
Definition.

Using the Invoker servlet in a production environment are not recommended and
is unsupported.

In addition, when I read the <core servlet and Java server pages:2nd editon>, the book just downplayed

Said a phrase related to the/servlet mapping. This, I do not know how many heroes have been stumped!



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.