English 中文(简体)
无法用 Tomcat 的 cs 运行 jsp 。
原标题:can t run jsp with css from tomcat

i have problem running my project from Tomcat. i used IDE before and never faced this problem till now. i have my jsp with a link to css, that looks like this:

<%@page import="data.PageData"%>
<%@page import="dao.pageDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="pagedata" class="data.PageData" scope="request"></jsp:useBean>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title><jsp:getProperty name="pagedata" property="title" /></title>
    <link rel="stylesheet" href="main.css"> 
</head>
<body>
<div id="big_wrapper">
    <header id=top_header>
      <h1>Site Header</h1>
    </header>
 <div id="new_div">
  <section id="main_section">
  <jsp:getProperty property="maintext" name="pagedata"/> 

  </section>
  <aside id="side_menu">
    <%= request.getAttribute("pagemenu") %>
  </aside>
  </div>
  <footer id="the_footer">
    Copyright  2012 &copy;
  </footer>
  </div>
</body>
</html>;

i put it in my tomcat s project root directory, just where i have my jsp. but whenever i try to run it, it shows my jsp page, but with no styles (it doesn t see main.css). what should i do to display it with styles? p.s. should i put smth in web.xml?

问题回答

什么是 URL 映射? 您的主. cs 是在没有路径的情况下指定的, 所以它与您的 URL 映射中的路径相对, 那就是您应该放置主. cs 文件的位置 。

要测试您是否能够访问主. css, 在 Firefox 中, 您可以查看 html 源代码并点击 主. css 。 Firefox 将引导您找到主. cs 源。 如果您无法看到您期待 cs 代码, 那么您的路径就错了 。 您可能想要做类似的事情 。

<link rel="stylesheet" href="/my/url/mapping/path/main.css"> 

<link rel="stylesheet" href="../../my/relative/path/main.css">

If it w或ks bef或e when you run it with IDE, it might be that your IDE start your webapp without context path and when you run it under tomcat it is with context path. You need to make sure that the css 或 other resource are of c或rect path.

对不起,打扰你的家伙, 我发现错误, 这是在 xml 映射中, 我不应该在 URL 模式的结尾加上"/"





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签