JSP 인쇄 캐리지 리턴 (CR)을 만드는 방법이 있습니까?
문제
현재 JSP를 사용하여 일부 vCard를 생성합니다.라인이 캐리지 리턴 ( cr )으로 구분되지 않고 JSP가 라인 피드 ( lf )를 사용하는 것으로 보이지 않는 한 일부 플랫폼이 생성 된 vCards를 인식하지 못했습니다.기본 행은 줄을 분리합니다.
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.