链接css文件会破坏html表格式

我正在研究一些 Java Servlets,基本上我正在将sql查询的结果输出到表中.我在html代码中有一些表格的基本格式,但我也想链接一个css文件.

每当我链接样式表(即使是空白样式表,或者与表中的html标记具有相同属性的样式表)时,它只会破坏表中的任何格式,并将结果作为一个连续列表输出.

任何建议都将是一个很大的帮助.

这是我的servlet代码:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String category = request.getParameter("categoryname"); 
    AlbumDAO albumData = new AlbumDAO();
    ArrayList<AlbumBean> albums = albumData.findFromCategory(category);

    PrintWriter out = response.getWriter();
    response.setContentType("text/html");


    String title = category + " albums";
    String stylesheet = "<link rel=\"stylesheet\" type=\"text/css\" href=\"/CSS/stylesheet.css>";

    out.println("<!DOCTYPE html><html>");
    out.println("<head>");
    out.println("<title>" + title + "</title>");
    out.println(stylesheet);
    out.println("</head>");
    out.println("<body>");
    out.println("<Center><H1>" + category + " albums</Center>");

    out.println("<table border=\"1\" cellspacing=\"5\" cellpadding=\"5\">"
            + "<tr><th>ID</th><th>Artist</th><th>Title</th><th>Image Name</th><th>Tracks</th><th>Price</th><th>In Stock</th></tr>");

    for (AlbumBean a : albums){
        out.println("<tr><td> "+ a.getRecording_id() + "</td>");
        out.println("<td>" + a.getArtist_name() + "</td>");       
        out.println("<td> " + a.getTitle() + "</td>");
        out.println("<td> " + a.getCategory() + "</td>");
        out.println("<td> " + a.getImage_name() + "</td>");
        out.println("<td> " + a.getPrice() + "</td>");
        out.println("<td> " + a.getStock_count() + "</td>");
        out.println("</tr>");

        }
    out.println("</table>");
    out.println("</body>");

    out.println("<footer><a href = \"index.html\"> let's go home</a></footer>");
    out.println("</html>");
}

最佳答案 看起来您没有关闭链接语句中的引号

String stylesheet = "<link rel=\"stylesheet\" type=\"text/css\" href=\"/CSS/stylesheet.css\">";
点赞