我知道有人问过这个问题,但这并没有解决我的问题并尝试了许多不成功的事情:
我的spring webapp项目目录很标准,看起来像:
/webapp/js/* eg. /webapp/js/query.jeditable.js
/webapp/WEB-INF/jsp/*
/webapp/WEB-INF/web.xml+
/webapp/WEB-INF/spring-servlet.xml - dispatcher servlet config
/webapp/WEB-INF/spring-security.xml - spring security config
我正在尝试从jsp url中获取js中的javascript文件,该文件也通过spring security url matcher进行过滤。 这是我的web.xml:
的web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<display-name>Welcome to projectBananaStand</display-name>
<description>
Welcome to 'projectBananaStand' Add Event Test
</description>
<context-param>
<param-name>jmxLogEnabled</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/js/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.jpmorgan.tyger.listeners.JMXLog4JContextListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>registerName</param-name>
<param-value>projectBananaStand</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<error-page>
<error-code>500</error-code>
<location>/custError.jsp</location>
</error-page>
<distributable />
</web-app>
这是我试图获取js文件的jsp代码:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<!-- DataTables CSS -->
<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css">
<!-- DataTables -->
<script type="text/javascript" charset="utf8" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.js"></script>
<!-- editable datatables -->
<script src="/js/jquery.jeditable.js" type="text/javascript"></script>
<script src="/js/jquery.dataTables.editable.js" type="text/javascript"></script>
<script src="/js/addEvent.js" type="text/javascript"></script>
<script src="http://cdn.jsdelivr.net/jquery.validation/1.13.1/jquery.validate.js" type="text/javascript"></script>
这是spring-servlet.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:annotation-config />
<!-- declaring base package -->
<context:component-scan base-package="com.banana.controller" />
<mvc:annotation-driven/>
<!-- adding view resolver to show jsp's on browser -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value></property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean class="org.springframework.context.support.ResourceBundleMessageSource"
id="messageSource">
<property name="basename" value="messages" />
</bean>
</beans>
所有应用级bean和Spring安全相关配置已在applicationContext.xml中定义,并通过contextListener添加
我无法使用
<mvc:resources mapping="/js/**" location="/js/" />
因为我使用的是Spring 3.0.3,并且不想升级整个框架。
我尝试仅使用spring mvc 3.1的xmlns定义,但仍然导致错误 - 找不到mvc:resource声明。
我尝试使用url模式
映射默认servlet*.js, /js/**, and /somethingelse/*
他们打破了春季安全默认登录页面加载。弹出安全登录页面的资源未找到错误。
在jsp文件中尝试了不同的标记,包括
source="<c:url value="something" />"
请帮忙,如何在没有mvc:resource mapping
的情况下将javascript文件包含在jsp中,或者在不更改所有spring框架版本的情况下使用mvc:resource mapping
并使用不同的
xmlns schemaLocation
而不是default servlet
有没有办法包含文件而不将它们视为网址?我究竟做错了什么? 非常感谢帮助,因为我花了很多时间与此作斗争。 感谢
答案 0 :(得分:0)
将你的js文件夹保存到/ WEB-INF / jsp /文件夹中,这可能是我没试过的工作。