Is there any way to make a JSP print carriage returns (CR)?
I'm currently generating some vCards using JSP. I found out some platforms don't recognize these generated vCards unless their lines are separated by Carriage Returns (CR), and JSP seems to use just Line Feed (LF) by default to separate lines.
Do you guys know any way to tell the JSP to include a CR between each line?
I hope someone has a clue, cause I haven't found much out开发者_StackOverflow中文版 there...
Thanks in advance!
If you need to emit non-HTML format, then you should be using a servlet instead of a JSP. This way you're not dependent on the JspServlet and/or appserver specifics how the output is been generated. More than often you simply cannot control this.
Using a servlet is relatively simple. Create a class which extends HttpServlet
and implement the doGet()
method like follows:
response.setContentType("text/x-vcard");
response.setCharacterEncoding("UTF-8");
PrintWriter writer = response.getWriter();
writer.write("BEGIN:VCARD" + (char) 10);
// ...
Map this in web.xml
on an url-pattern
of /vcard/*
or *.vcf
or whatever and use the request servletpath/pathinfo/params to generate output dynamically based on the URL.
精彩评论