JSP无法打开CSS,图像和JS [英] JSP doesn't open CSS, Images and JS

查看:99
本文介绍了JSP无法打开CSS,图像和JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将CSS,JS和IMG放到我的JSP上,但不起作用,这很奇怪,因为我使用了c:url和"jstl/core"

I'm trying to put CSS, JS and IMGs on my JSP, but doesn't work, it's strange because I use c:url and "jstl/core"

我使用的是JSP,jstl和servlet,没有框架.

I'm use JSP, jstl and servlet, no frameworks.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html>
<html>    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>clientes atuantes</title>
        <link rel="stylesheet" href="<c:url value="/bootstrap/css/bootstrap.min.css"/>">
        <link rel="stylesheet" href="<c:url value="/css/layout.css"/>">
        <script type="text/javascript" src="<c:url value="/bootstrap/js/jquery-1.12.0.js" />"></script>
        <script type="text/javascript" src="<c:url value="/bootstrap/js/bootstrap.min.js" />"></script>
    </head>
    <body>

        <main>
            <div class="col-md-12">
                <div class="panel panel-default espacamentoExterno5">

                    <div class="panel-body">
                        <p><img src="<c:url value="/img/ativo.gif"/>" /> ativo</p>
                        <p><img src="<c:url value="/img/congelado.gif"/>" /> congelado</p>
                        <p><img src="<c:url value="/img/cancelado.gif"/>" /> cancelado</p>

                    </div>
                </div>
            </div>
        </main>
    </body>
</html>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xmlns:web="http://java.sun.com/xml/ns/javaee" 
         xmlns="http://java.sun.com/xml/ns/javaee" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

  <display-name>PainelProduct</display-name>


</web-app>

推荐答案

URL模式"/"对Web服务器具有特殊含义.它用于能够提供静态内容的默认servlet映射.静态内容是JS,CSS,图像,html资源.将这些文件定向到servlet是错误的,因为它不能提供静态内容.

The url pattern "/" has a special meaning to the web server. It's used for default servlet mapping which is capable of serving the static content. The static content is JS, CSS, images, html resources. Directing these files to your servlet is wrong, because it's not capable to serve the static content.

将servlet映射更改为@WebServlet(urlPatterns="/incidente")

Change the servlet mapping to something @WebServlet(urlPatterns="/incidente")

并使用URL localhost:8080/PainelProduct/incidente转发到jsp页面.

and use url localhost:8080/PainelProduct/incidente to forward to jsp page.

选中此问题,以了解有关servlet和servlet映射的更多信息将特定的servlet映射为Tomcat中的默认servlet .

Check this question to learn more about servlets and servlet mapping Mapping a specific servlet to be the default servlet in Tomcat.

这篇关于JSP无法打开CSS,图像和JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆