Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
518 views
in Technique[技术] by (71.8m points)

java - how to redirect url to jsp in web.xml

(Should be an easy one-)

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>

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


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>

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...