0

我需要在 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页面仍然格式化:(

4

0 回答 0