将CSS嵌入servlet中

时间:2012-04-07 12:56:03

标签: css tomcat servlets

我需要在servlet中嵌入样式表和javascript。

import java.io.*;
import javax.servlet.*;
import java.util.*;
import javax.servlet.http.*;

public class StyleServlet extends HttpServlet
{
     public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException
         {


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

        out.println("<html>");
        out.println("<head>");
        out.println("<link rel='stylesheet' type='text/css' href='" + request.getContextPath() +  "/mystyle.css' />");    
        out.println("</head>);

        out.println("<h3>demo</h3>");
        }
}

我已将.css放在tomcat \ webapps \ myproject \ mystyle.css

我也试过这种方式

out.println("</style>");

out.println("<link rel="+"stylesheet"+" type="+"text/css");
out.println("href=" + request.getContextPath() +  "/mystyle.css/>");     
out.println("</style>");

但我的html页面仍然是格式化的:(

0 个答案:

没有答案