Servlet 映射失败
现在我有以下问题: 我正在尝试使用 Tomcat 7 和 JSP 创建一个网站。 但我无法正确配置服务器。 我想要一个在浏览器地址栏中显示类似 mydomain.com/about 的网站,而不包含任何 *.jsp 或 *.html。 为了实现这一点,我有一个重定向 Bean,由 JSP 页面调用,解析请求的 URI 并返回应转发到的 JSP 文件的路径。问题是 web.xml 中的 servlet 映射 在那里,我尝试为例如 /about 创建一个 servlet 映射,该映射映射到调用该 bean 的redirect.jsp。问题是,我收到以下异常:
javax.servlet.ServletException:没有为 servlet 重定向指定 servlet 类
这是 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:正确调用了 index.jsp,因为它位于欢迎文件列表。问题是重定向到其他站点而不在地址栏中显示其路径。
也许有一种方法可以在 Javabean 中转发。这可以由 servlet 映射中的
标签调用。
提前感谢您的帮助! 最大限度
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此错误仅意味着在
web.xml
中没有定义名称为redirect
的 servlet,例如或
相应地修复您的
web.xml
。与具体问题无关,我建议使用单个
Filter
和一些(XML?)配置文件来代替。类似于 Tuckey 的 URL 重写过滤器,它与 Apache HTTPD 的mod_rewrite
非常相似。This error just means that there's no servlet with the name
redirect
been definied inweb.xml
likeor
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'smod_rewrite
.对不起,
这只是 web.xml 中上面的一个块,
不是解决方案。
我非常确定,需要一个定义 servlet 的节点。
但正如我所说,我需要一个 JSP 文件。
Sorry,
this is just one block above in the web.xml
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.