[opencms-dev] Declare http status (404/301/...) in JSP

raphael.cavalcanti raphael.cavalcanti at almg.gov.br
Tue Feb 5 22:22:17 CET 2019


Hello! 

Does anyone know if the problem described on the original post has now been
resolved? Yes, i know, 14 years have passed, but i'm trying to the the same
thing as the original author and having the same problems.

Complementing the original post, what i'm trying to do is validate a few
parameters expected by my JSP before running it.
So, for example, my page "http://mytest.com?myparam=%5Ctext", in which
"myparam" should only receive integer values.
What i want to do is, at the begining of my JSP, do that validation, and if
a value that is not an integer is identified then do a
"response.sendError(400);" for "bad request".

I've tried many things and none of then worked:

<%
	//1st try
	CmsStaticExportResponseWrapper respw = new
CmsStaticExportResponseWrapper(response);
	respw.sendError(400);

	//2nd try
	CmsJspBean cmsBean = new CmsJspBean();
	cmsBean.init(pageContext, request, response);
	cmsBean.setStatus(400);
	
	//3rd try
	cmsBean.getResponse().sendError(404, "Invalid params.");
	
	//4th try
	OpenCmsServlet ocs = new OpenCmsServlet();
	ocs.handle(request, response, "400");

	//5th try
	response.sendError(400, "Invalid params.");
	
	//end of test
	out.println("END OF THE TEST...<br />");
%>

All of those attempts end with the message "END OF THE TEST..." printed on
the screen. What i wanted was for the page to redirect to the "handle400"
error page.

According to this reference, the best practice would be to do that
validation on the servlet, before redirecting to the jsp, but i don't know
if that is possible on OpenCMS:

https://stackoverflow.com/questions/7109419/what-is-the-best-practice-for-validating-parameters-in-jsp/

Thanks in advance for any help!



--
Sent from: http://opencms.996256.n3.nabble.com/



More information about the opencms-dev mailing list