【问题标题】:Include a bootstrap css file to a spring project jsp file将引导 css 文件包含到 spring 项目 jsp 文件中
【发布时间】:2016-04-16 18:29:20
【问题描述】:

我想将引导 css 文件添加到我的 spring 项目中。

这是应该包含引导 css 文件的 jsp 文件。

<%@ 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 文件中。

【问题讨论】:

    标签: java css spring twitter-bootstrap jsp


    【解决方案1】:

    在您的 Spring MVC 应用程序中,所有请求都由 DispatcherServlet 处理,您必须配置一个资源处理程序来处理任何静态资源,如 Javascript 文件或 CSS 文件。

    由于您已在 spring config 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,但要确保你的 webapp 上下文是正确的:

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

    【讨论】:

    • 这很好 :) 谢谢你这个 最后也应该添加到 configurarion xml 文件中。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-05
    • 2019-06-05
    • 1970-01-01
    • 2017-09-30
    • 2019-05-18
    • 1970-01-01
    • 2016-03-15
    相关资源
    最近更新 更多