2

I don't have any idea how i can link my css a js file

Please healp. I only get this request: No mapping found for HTTP request with URI [/LiblaryProject/WebContent/js/script.js] in DispatcherServlet with name '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>

and in my Home.jsp I have someting like:

 <script src="<c:url value="WebContent/js/script.js" />"></script>
  <link href="/css/custom.css" rel="stylesheet" type="text/css" />
Domv12
  • 65
  • 6

2 Answers2

0

By using the url-pattern / you have overriden the container`s default servlet. This is the servlet which serves static content from the root of the web application. To keep your mapping you need to configure the Spring default servlet handler. How this works is that requests for static resources now comes through Spring instead of default servlet. Spring will now lookup the container defualt servlet based on container type. To achieve this add the line below to your application config file

<mvc:defualt-servlet-handler/>
ekem chitsiga
  • 5,523
  • 2
  • 17
  • 18
0

In your controller accepts requests such as "/" because in your web.xml this way. Try changing this:

Example:

Web.XML:

<servlet-mapping>
    <servlet-name>library</servlet-name>
    <url-pattern>.*htm</url-pattern> 
  </servlet-mapping>