public class MyclassReader extends HttpServlet{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");//setting the content type
PrintWriter pw=res.getWriter();//get the stream to write the data
//writing html in the stream
pw.println("<html><body>");
pw.println("Welcome to servlet");
pw.println("</body></html>");
pw.close();//closing the stream
}
After doing mvn clean install and cargo.run CMS starts but gives me 404 when request the page
Hello, first of all please be aware that there are multiple web.xml (for cms, essentials and site), so make sure that you are working in the correct webapp.
I would also like to ask, what are you trying to achieve here? A raw servlet is probably not the best choice for whatever you are trying to do
This one will be hard to figure out, but basically there is a filter in your way which will redirect away from unapproved paths. The filter is the “NavAppRedirectFilter”. You can override this in the web.xml, but I’m not sure what the effects will be. Probably fine, but I cannot guarantee. Something like this:
I would like to have a servlet because I want to access some parts outside the CMS but I need to use some object created in the CMS. I am not sure if I am explaining. Let´s say that is a little experiment form myself.
I will try the filter, but I can´t find it in my project, so can I add it to my CMS´s web.xml???
The filter is contributed by a web-fragment in an included library. It’s not in your project but in hippo-cms-engine. web.xml configuration will override the web-fragment. Use the config I have given above, ie the “actuator” is what is in the web-fragment so it needs to be included.
I would configure this as the last filter in your web.xml. The order matters.
Upgrading a project where there are CMS servlets in use I’m happy to find this solution.
I do have a question: In my case the filter only seems to work if I set url-pattern to /cms/*. Could that give problems?
Filter mappings should already be relative to the context root of the application. If anything I would expect the filter to not work with that mapping, but perhaps there is something else going on in those projects I am not aware of.
Yes, I thought so too. I haven’t yet had opportunity to check this on OD2 platform, so will find out if this was only local necessary.
Thanks for your reaction!