import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.Date;
public class HelloServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<html><head><title>only for test</title></head><body>Hello, world!html version</body></html>");
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
doGet(request, response);
}
}
如果我將內容類型設置爲xhtml
,那麼Web瀏覽器會自動打開保存文件對話框。爲什麼會發生?爲什麼我需要在此Java Servlet中將content-type設置爲html?
你是XHTML overhype的另一個受害者。將鼠標置於放置問題的'[xhtml]'標籤之上,直到popbox顯示出來,然後在其中單擊*「info」*鏈接,並獲得明智的結果。只需使用'text/html'。 – BalusC 2014-12-30 12:28:44