Reputation: 5668
How do I map a url to a HttpServlet class in tomcat.
Example I want requests /calc to be handled by Calc.java
so a request to 127.0.0.1:800/calc
would call:
public class Calc extends HttpServlet {
/* ... */
}
Upvotes: 0
Views: 89
Reputation: 66637
I think this configuration should be in web.xml
in your war
file, not in tomcat.
If you are using Servlet3.0 then you may use annotations also.
@WebServlet(urlPatterns="/yoururl")
Upvotes: 0
Reputation: 15219
If you're on tomcat7 it's as easy as adding the annotation:
@WebServlet(urlPatterns="/calc")
public class Calc extends HttpServlet {
/* ... */
}
Upvotes: 2
Reputation: 16158
Add following configuration in your web.xml
<servlet>
<servlet-name>calcServlet</servlet-name>
<servlet-class>packagename.Calc</servlet-class> <!-- change the name of package according to your class -->
</servlet>
<servlet-mapping>
<servlet-name>calcServlet</servlet-name>
<url-pattern>/calc</url-pattern>
</servlet-mapping>
Upvotes: 0
Reputation: 139921
I think you would benefit greatly from reading the Tomcat manual section on "your first webapp", which covers this.
Upvotes: 0