如何在web.xml中将url重定向到jsp [英] how to redirect url to jsp in web.xml

查看:752
本文介绍了如何在web.xml中将url重定向到jsp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(应该很简单 - )

(Should be an easy one-)

如何将模式yada * .js的所有网址重定向到我的特定jsp中。

将添加到我的web.xml工作中:

How can I redirect all urls of the pattern yada*.js into a my specific jsp.
will this addition to my web.xml work:

<servlet-mapping>
        <servlet-name>MySpecific.jsp</servlet-name>
        <url-pattern>yada*.js</url-pattern>
</servlet-mapping>

或者我必须为此目的使用javax.servlet.filter?

or perhaps I must use javax.servlet.filter for that purpose?

推荐答案

我将这些文件放在名为 / yada 的文件夹中,然后使用 url-pattern / yada / *

I'd drop those files in a folder called /yada and then use an url-pattern of /yada/*.

如果你不喜欢我不想这样做,然后在过滤器中手动确定它确实是唯一的手段。

If you don't want to do that, then hand-determining it in a filter is indeed the only resort.

更新:根据您的更新,您实际上还有第二个问题,这个问题在您的初始问题中并不明显:如何将JSP文件声明为servlet?。答案是:使用< jsp-file> 而不是< servlet-class>

Update: as per your update, you actually have a second question which wasn't directly obvious from your initial question: "How to declare a JSP file as a servlet?". The answer is: use <jsp-file> instead of <servlet-class>.

<servlet>
    <servlet-name>foo.jsp</servlet-name>
    <jsp-file>/foo.jsp</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>foo.jsp</servlet-name>
    <url-pattern>/foo/*</url-pattern>
</servlet-mapping>

然而,正如评论中所述,这不是最佳做法。这有点像JSP文件中的原始Java代码,您应该避免在所有程度上。

Nevertheless, as stated in the comments, this is not the best practice. This smells to raw Java code in a JSP file which you should avoid to all extent.

这篇关于如何在web.xml中将url重定向到jsp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆