Javascript cannot be found to be loaded from the JSP/controller path
When I try to load a js file externally I keep getting a 404 err开发者_运维问答or in the firebug NET console. The JSP can't seem to be detecting the js file and I have tried many combinations with no luck, also searched the net without any real progress, can anyone point out what I am doing wrong here?
Web XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>GreenwhichProject</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
Workspace Path Directory Structure Picture
http://img26.imageshack.us/i/workspacepath.jpg/
PROJECT
|
WebContent
|
js
|_jquery-1.5.js
WEB-INF
|_dispatcher-servlet.xml
|_web.xml
jsp
|_OrderTaxi.jsp
Additionally this is how a normal controller function looks like
@RequestMapping(value="/taxiOrder/loadOrderTaxiServicePage.htm", method = RequestMethod.GET)
public String showOrderTaxiServicePage(ModelMap model){
return "orderTaxi";
}
So when I have to access a page it will usually be the /"controllerName"/"functionHtmName"
dispatcher-servlet.xml has a view resolver if it will be useful for figuring out the problem
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
Additionally this is how I am looking for the JS in my JSP file
<script type="text/javascript" src="/js/jquery-1.5.js"></script>
Please try
<script type="text/javascript" src="../js/jquery-1.5.js"></script>
Try <script type="text/javascript" src="/[your_apps_contextroot]/js/jquery-1.5.js"></script>
with your_apps_contextroot
being the context root you defined for your application (might be the war file's base name by default).
精彩评论