有没有办法制作JSP打印托运返回(CR)?
题
我目前正在使用JSP生成一些VCARD。我发现一些平台不识别这些生成的vCards,除非它们的线路通过回车( cr )分隔,而JSP似乎只使用行源( lf )默认为单独的行。
你们是否知道任何方式告诉JSP在每行之间包含CR?
我希望有人有一个线索,因为我没有找到太多...
提前感谢!
解决方案
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.
不隶属于 StackOverflow