2016-01-12 73 views
2

我想引導css文件添加到我的春天項目。包括一個引導css文件到春天項目JSP文件

enter image description here

這是JSP文件,其中應包括引導css文件。

<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> 
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> 
    <html> 
    <head> 
     <title>Login</title> 
    </head> 
    <body> 
     <h2>Login With Database Application</h2> 
     <form:form method="post" action="login" modelAttribute="loginuser"> 
      <table> 
       <tr> 
        <td>Login ID</td> 
        <td><input type="text" name="loginid" id="loginid" path="loginid" /></td> 
       </tr> 
       <tr> 
        <td>Password</td> 
        <td><input type="password" name="password" id="password" path="password" /></td> 
       </tr> 
      </table> 

      <button class="btn btn-primary"type="submit">Login</button> 
      <a href="newuser">New User</a> 
     </form:form> 
    </body> 

這是xml配置文件。

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> 

    <context:component-scan base-package="com.epic.logindb.controller"></context:component-scan> 
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
     <property name="prefix" value="/WEB-INF/jsp/" /> 
     <property name="suffix" value=".jsp" /> 
    </bean> 


    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
     <property name="driverClassName" value="com.mysql.jdbc.Driver" /> 
     <property name="url" value="jdbc:mysql://localhost:3306/users" /> 
     <property name="username" value="root" /> 
     <property name="password" value="" /> 
    </bean> 

    <bean id="userlogin" class="com.epic.logindb.dao.UserLogin"></bean> 
    <bean id="loginuser" class="com.epic.logindb.model.LoginUser"></bean> 
    <bean id="user" class="com.epic.logindb.model.User"></bean> 
    <bean id="edituser" class="com.epic.logindb.model.User"></bean> 

</beans> 

請你幫忙把引導文件集成到這個jsp文件。

回答

1

在Spring MVC應用程序的所有請求被處理DispatcherServlet,你必須處理任何靜態資源,如JavaScript文件或CSS文件配置資源處理程序。

既然你已經包含在Spring配置XML的MVC空間文件,你可以使用下面的標籤:

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

你在做什麼在這裏被映射在URI resources所有請求以服務內部的靜態文件文件夾稱爲資源。

要在JSP鏈接CSS您可以使用JSTL標籤:

<link rel="stylesheet" href='<c:url value="/resources/bootstrap/bootstrap.min.css" />' /> 

或者不JSTL,但要確保你的web應用上下文是正確的:

<link rel="stylesheet" href="/basecontext/resources/bootstrap/bootstrap.min.css" /> 
+1

這是做工精細的:)謝謝你這最後還應該添加到configurarion xml文件中,非常感謝您 – Shalika