Aubergine
Aubergine

Reputation: 6042

Web application URL access java

I am trying to understand how the requests works. Unfortunately I was thrown at coding first and only then at understanding.

I wrote some really basic webapplication in java few years ago and it did work as expected. On its main web-page(.jsp) I had following as one of the menu buttons:

<p><a href="home.jsp">test</a></p>

I am currently writing new webapp and forgot a lot. This time I am doing it with Spring MVC and properly. I can't really understand why this snippet no longer brings me to the home.jsp in current webapplication and why at first I did use it in old app.

Apache gives: The requested resource () is not available.

It is not that I need that sort of direct interaction, it is just I am trying to understand whether resources are accessible via URL? Does Spring MVC brings me extra security, where only servlet handled requests can result in a view? Am I missing something really trivial?

Moreover in that same old web app menu I had direct link to the servlet, but currently I can't make such direct reference to the servlet in the new webapp. I can make relevant request which will be captured by the servlet, but not by the name of it.

Apache gives: The requested resource () is not available.

Reference to servlet from menu:

<% if((String) session.getAttribute("passengerFound") != null){ %>
<a href="TripRecentBook"><img style="border:0" src="menuButtons/My Trips.png" alt="My Trips"/></a> <%} %>

Thanks, I bet it is really simple. I really want to understand, please help. I know that it has something to do with Front Controller(dispatcherServlet), but I can't form logical and firm explanation in my head.

Upvotes: 0

Views: 486

Answers (2)

gotomanners
gotomanners

Reputation: 7926

You might just be missing a "/" as in "/home.jsp" instead of "home.jsp"

Upvotes: 0

pap
pap

Reputation: 27614

it is just I am trying to understand whether resources are accessible via URL

In short, no. The default behavior and recommended configuration when using Spring MVC is to map the Spring DispatcherServlet to the / url pattern, meaning ALL requests are sent to the DispatcherServlet. Out of the box, the dispatcher-servlet will NOT service any requests for static resources. If this is desired, the two main options are

  1. Map the DispatcherServlet to another pattern than root, effectivly isolating the Spring MVC portion to a sub-context
  2. Add a resource-mapping to your spring context (your applicationContext.xml).

<mvc:resources mapping="/res/**" location="/res/" />

This above would tell spring mvc to treat all request to /res/** as requests for static resources (like images etc) and that those resources are physically located in the /res/ folder in the application root.

Upvotes: 2

Related Questions