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);
}
}
If I set the content-type to xhtml, then the web-browser would automatically open the save-file dialog. Why would this happen?
First of all, note that the right content-type for xhtml is not xhtml or text/xhtml, but application/xhtml+xml.
Anyway, you'll need to check whether the user agent can actually accept this content-type by examining the Accept HTTP request header. According to the W3C recommendation:
application/xhtml+xml (with either no "q" parameter or a positive "q" value) deliver the document using that media type.text/html (with either no "q" parameter or a positive "q" value) deliver the document using that media type.text/html.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With