<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hey there, 
<div class=""><br class="">
</div>
<div class="">I succeeded sending headers by using the „top response“, that’s the original http response. </div>
<div class="">Here’s what I did:</div>
<div class="">
<pre style="background-color: rgb(255, 255, 255); font-family: Menlo-Regular; font-size: 8.3pt;" class="">CmsFlexController flexController = CmsFlexController.<span style="font-style:italic;" class="">getController</span>(<span style="color:#660e7a;font-weight:bold;" class="">pageContext</span>.getRequest());<br class="">HttpServletResponse topResponse = flexController.getTopResponse();<br class="">topResponse.setContentType(<span style="color:#660e7a;font-weight:bold;font-style:italic;" class="">MIME_TYPE_PDF</span>);<br class="">topResponse.setContentLength(pdf.<span style="color:#660e7a;font-weight:bold;" class="">length</span>);<br class="">topResponse.setHeader(<span style="color:#008000;font-weight:bold;" class="">"Content-Disposition"</span>,<span style="color:#008000;font-weight:bold;" class="">"inline; filename="</span>+fileName);</pre>
</div>
<div class="">I think with the topResponse you might also be able to send an error as well, but I’m not sure and I can’t try right now.</div>
<div class="">As for redirecting to the error page, I’m not sure if that’s possible by sending an error. Maybe the dispatcher is already done, so maybe you have to do the redirect yourself like this (again I can’t try).</div>
<div class="">
<pre style="background-color: rgb(255, 255, 255); font-family: Menlo-Regular; font-size: 8.3pt;" class="">flexController.getTopResponse().sendRedirect(<span style="color:#660e7a;font-weight:bold;" class="">errorRedirect</span>);</pre>
</div>
<div class=""><br class="">
</div>
<div class="">Hope that helps, best</div>
<div class=""><br class="">
</div>
<div class="">Kai</div>
<div class="">
<div><br class="">
</div>
<div><br class="">
</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">Am 05.02.2019 um 22:22 schrieb raphael.cavalcanti <<a href="mailto:raphael.cavalcanti@almg.gov.br" class="">raphael.cavalcanti@almg.gov.br</a>>:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Hello! <br class="">
<br class="">
Does anyone know if the problem described on the original post has now been<br class="">
resolved? Yes, i know, 14 years have passed, but i'm trying to the the same<br class="">
thing as the original author and having the same problems.<br class="">
<br class="">
Complementing the original post, what i'm trying to do is validate a few<br class="">
parameters expected by my JSP before running it.<br class="">
So, for example, my page "<a href="http://mytest.com?myparam=%5Ctext" class="">http://mytest.com?myparam=%5Ctext</a>", in which<br class="">
"myparam" should only receive integer values.<br class="">
What i want to do is, at the begining of my JSP, do that validation, and if<br class="">
a value that is not an integer is identified then do a<br class="">
"response.sendError(400);" for "bad request".<br class="">
<br class="">
I've tried many things and none of then worked:<br class="">
<br class="">
<%<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>//1st try<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>CmsStaticExportResponseWrapper respw = new<br class="">
CmsStaticExportResponseWrapper(response);<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>respw.sendError(400);<br class="">
<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>//2nd try<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>CmsJspBean cmsBean = new CmsJspBean();<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>cmsBean.init(pageContext, request, response);<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>cmsBean.setStatus(400);<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>//3rd try<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>cmsBean.getResponse().sendError(404, "Invalid params.");<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>//4th try<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>OpenCmsServlet ocs = new OpenCmsServlet();<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>ocs.handle(request, response, "400");<br class="">
<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>//5th try<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>response.sendError(400, "Invalid params.");<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span><br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>//end of test<br class="">
<span class="Apple-tab-span" style="white-space:pre"></span>out.println("END OF THE TEST...<br />");<br class="">
%><br class="">
<br class="">
All of those attempts end with the message "END OF THE TEST..." printed on<br class="">
the screen. What i wanted was for the page to redirect to the "handle400"<br class="">
error page.<br class="">
<br class="">
According to this reference, the best practice would be to do that<br class="">
validation on the servlet, before redirecting to the jsp, but i don't know<br class="">
if that is possible on OpenCMS:<br class="">
<br class="">
<a href="https://stackoverflow.com/questions/7109419/what-is-the-best-practice-for-validating-parameters-in-jsp/" class="">https://stackoverflow.com/questions/7109419/what-is-the-best-practice-for-validating-parameters-in-jsp/</a><br class="">
<br class="">
Thanks in advance for any help!<br class="">
<br class="">
<br class="">
<br class="">
--<br class="">
Sent from: http://opencms.996256.n3.nabble.com/<br class="">
_______________________________________________<br class="">
This mail is sent to you from the opencms-dev mailing list<br class="">
To change your list options, or to unsubscribe from the list, please visit<br class="">
http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev<br class="">
<br class="">
<br class="">
<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>