java - create servlet url-pattern with "/" -


i've created servlet named maincontent. , have such mapping

<servlet>     <display-name>maincontent</display-name>     <servlet-name>maincontent</servlet-name>     <servlet-class>ge.test.servlet.maincontent</servlet-class> </servlet> <servlet-mapping>     <servlet-name>maincontent</servlet-name>     <url-pattern>/main</url-pattern> </servlet-mapping> 

so, when go link: //localhost:8080/myappl/main enter servlets doget() method. create requestdispatcher forward index.jsp.

everything works!

requestdispatcher rd = context.getrequestdispatcher("/index.jsp?language="+ lang); rd.forward(request, response); 

everything works!

question:

now need change url-pattern. need that-:when enter localhost:8080/myappl/ need redirected servlet. create that:

<url-pattern>/</url-pattern>

ok, works! i'm redirected servlet. but wrong happend here. when servlet created requestdispatcher forward , there no images , css in index.jsp. when see in firebug console, i've seen errors:

resource interpreted stylesheet transferred mime type text/html: "http://localhost:8080/myapp/font/font_big.css". localhost/:15 resource interpreted image transferred mime type text/html: "http://localhost:8080/myapp/img/company.gif". 

how can fix that?

yes, @dwb pointed, '/' context problematic url pattern , causes problem.

use

<servlet-mapping>     <servlet-name>mainservlet</servlet-name>     <url-pattern></url-pattern> </servlet-mapping> 

instead. "the servlet 3.0 way" this.

sources

[1] http://www.coderanch.com/t/366340/servlets/java/servlet-mapping-url-pattern

[2] how can map "root" servlet other scripts still runnable?


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -