mxcd
mxcd

Reputation: 2424

Servlet Mapping fails

Now I have the following problem: I am trying to create a website using Tomcat 7 and JSP. But I am not capable of configurating the server properly. I want a website that shows in the browsers address-bar something like mydomain.com/about without any *.jsp or *.html. In order to realize this I have a redirection Bean, that is called by a JSP-Page, parses the requested URI and returns the path of a JSP-File that should be forwarded to. The problem is the servlet mapping in the web.xml There i tried to create a servlet mapping for e.g. /about that is mapped to the redirect.jsp that calls the bean. The problem is, that I recieve the following exception:

javax.servlet.ServletException: No servlet class has been specified for servlet redirect

Here is the code of the web.xml:

<servlet-mapping>
    <servlet-name>redirect</servlet-name>
    <url-pattern>/engine</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>redirect</servlet-name>
    <url-pattern>/about</url-pattern>
</servlet-mapping>

BTW: The index.jsp is called properly because it is in the welcome-file-list. The problem is redirecting to the other sites without displaying their path in the address-bar.

Maybe there is a way to forward in a Javabean. This could be called by the <servlet-class>-tag in the servlet mapping.

Thanks for your help in advance! Max

Upvotes: 0

Views: 3786

Answers (2)

mxcd
mxcd

Reputation: 2424

Sorry, this is just one block above in the web.xml

<servlet>
    <servlet-name>redirect</servlet-name>
    <description>The main redirection thing</description>
    <jsp-file>/jsp/redirect.jsp</jsp-file>
</servlet>

<servlet-mapping>
    <servlet-name>redirect</servlet-name>
    <url-pattern>/engine</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>redirect</servlet-name>
    <url-pattern>/about</url-pattern>
</servlet-mapping>

Not the solution. Im quite sure, the wants a node where the servlet is defined. But as I said, I need a JSP-File instead.

Upvotes: 1

BalusC
BalusC

Reputation: 1109625

No servlet class has been specified for servlet redirect

This error just means that there's no servlet with the name redirect been definied in web.xml like

<servlet>
    <servlet-name>redirect</servlet-name>
    <servlet-class>com.example.YourServletClass</servlet-class>
</servlet>

or

<servlet>
    <servlet-name>redirect</servlet-name>
    <jsp-file>/redirect.jsp</jsp-file>
</servlet>

Fix your web.xml accordingly.


Unrelated to the concrete problem, I recommend to use a single Filter with some (XML?) config file for this instead. Something like Tuckey's URL rewrite filter, which is much similar to Apache HTTPD's mod_rewrite.

Upvotes: 4

Related Questions