4

I am working on some Java Servlets, and basically i am outputting the results of an sql query to a table. I have some basic formatting for the table in the html code, but i also want to link a css file.

Whenever i link a stylesheet (even a blank one, or one with the same attributes as the html tags in the table), it just destroys any formatting in the table, and outputs the results as one continuous list.

Any suggestions at all would be a great help.

Here's my servlet code:

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>");
}
Nile Daley
  • 41
  • 2
  • Did you make any progress with this? Have you checked your server access log to see if there are any 404 errors which cast any light on the issue – QuantumTiger Nov 27 '15 at 08:58

2 Answers2

1

Looks like you are not closing the quotation marks in your link statement

String stylesheet = "<link rel=\"stylesheet\" type=\"text/css\" href=\"/CSS/stylesheet.css\">";
QuantumTiger
  • 970
  • 1
  • 10
  • 22
0

I eventually solved it, the only thing was that i was thinking the folder CSS needed to be referenced as "/CSS/stylesheet.css"

whereas it was actually just "CSS/stylesheet.css" .

Thanks guys.

Nile Daley
  • 41
  • 2