I am working on some Java servlets, and basically I output the results of the sql query to a table. I have basic table formatting in html code, but I also want to link the css file.
Whenever I associate a stylesheet (even empty or one with the same attributes as the html tags in the table), it simply destroys any formatting in the table and displays the results as one continuous list.
Any suggestions at all would be a big help.
Here is 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 go home</a></footer>");
out.println("</html>");
}
source
share