我不知道如何将我的css链接到js文件
请Healp。我只收到这个请求: 在DispatcherServlet中找不到带有URI [/LiblaryProject/WebContent/js/script.js]的HTTP请求的映射,其名称为' library'
library-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.myliblary.*" />
<bean id="UserDAO" class="com.myliblary.dao.UserDAOImpl">
<constructor-arg>
<ref bean="sessionFactory" />
</constructor-arg>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/liblarydb" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
<tx:annotation-driven />
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<mvc:annotation-driven/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/Pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
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" >
<servlet>
<servlet-name>library</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>library</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
在我的Home.jsp中我有点像:
<script src="<c:url value="WebContent/js/script.js" />"></script>
<link href="/css/custom.css" rel="stylesheet" type="text/css" />
答案 0 :(得分:0)
通过使用url-pattern /,您已覆盖容器的默认servlet。这是一个servlet,它从Web应用程序的根目录提供静态内容。要保留映射,您需要配置Spring默认的servlet处理程序。这是如何工作的,现在对静态资源的请求来自Spring而不是默认的servlet。 Spring现在将根据容器类型查找容器defualt servlet。为此,请将以下行添加到您的应用程序配置文件
<mvc:defualt-servlet-handler/>
答案 1 :(得分:0)
在您的控制器中接受诸如&#34; /&#34;之类的请求;因为在你的web.xml中这种方式。尝试更改此内容:
示例:
<强> WEB.XML:强>
END IF;