0

I am making a "blog-platform" where users can write articles, and I want each article to get its own URL. Therefore, I'd like every page with the URL /blog/* to be sent to the same Servlet.

I have tried using web.xml like this:

<servlet>
    <servlet-name>BlogServlet</servlet-name>
    <servlet-class>package.BlogServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>BlogServlet</servlet-name>
    <url-pattern>/blog/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>MainServlet</welcome-file>
</welcome-file-list>

This doesn't work. /blog works, but /blog/ and /blog/any_string only gives off a timeout after a while. What am I doing wrong? Is there any other way I could implement this, other than parameters?

Sid Zhang
  • 972
  • 3
  • 9
  • 18
  • What's the name of the `.war `file? – Sid Zhang Apr 15 '15 at 16:46
  • I haven't exported the project to .war yet, and I'm still running it locally in eclipse. – Sindre Bøyum Apr 15 '15 at 16:49
  • Can you give an example of the whole URL? – Sid Zhang Apr 15 '15 at 16:49
  • I'm not sure if I understand your request. The URL that works right now is localhost:8080/project/blog. I want localhost:8080/project/blog/myarticle to send a request to the same BlogServlet. – Sindre Bøyum Apr 15 '15 at 17:08
  • If the container cannot find a resource mapped to the request path, it returns a 404 response immediately (and not a timeout). Are you sure the problem is not your Servlet itself? – ramp Apr 16 '15 at 06:17
  • The servlet works fine when requesting `/blog`. If you want to see the servlet code, I will provide it in a little while. – Sindre Bøyum Apr 16 '15 at 06:31

0 Answers0