0

Author Note: How include servlet output to jsp file I attempted this solution before I posted this problem as one of the includes with failure notes, it did not work for me.


Background/config:

  • Eclipse version: 2021-12 (4.22.0)

  • Project type: Dynamic Web Project

  • Language Java v16 and HTML

  • Tomcat version 9.0.56

  • Windows 10 64 bit home edition

  • Disabled firewall

I am trying to get a JSP to see a servlet via the call <jsp:include page = "SERVLET SOMETHING">>/jsp:include>

It works if I set it in a form and have the action to the same <"SERVLET SOMETHING">. Here is the file/folder hierarchy in question: Structure

I have tried every version I can think of with ../ or ./ if I use the full file path the server throws an error at the line interpretation. <jsp:include page="../java/servlets/ContextDemoServlet.java"></jsp:include> YIELDS


Message An exception occurred processing [/CallingServlets.jsp] at line [10]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: An exception occurred processing [/CallingServlets.jsp] at line [10]

7: <title>Calling Context Demo Servlet</title>
8: </head>
9: <body>
10: <jsp:include page="../java/servlets/ContextDemoServlet.java"></jsp:include>
11: </body>
12: </html>

Other attempts and their errors:

Include options that I have tried and failed at: <jsp:include page="ContextDemoServlet"></jsp:include> YIELDS Fragment "ContextDemoServlet" was not found at expected path /TestingServlets2/src/main/webapp/ ContextDemoServlet

<jsp:include page="/ContextDemoServlet"></jsp:include> YIELDS Fragment "/ContextDemoServlet" was not found at expected path /TestingServlets2/src/main/webapp/ ContextDemoServlet

<jsp:include page="./ContextDemoServlet"></jsp:include> YIELDS Fragment "./ContextDemoServlet" was not found at expected path /TestingServlets2/src/main/webapp/ ContextDemoServlet

<jsp:include page="../ContextDemoServlet"></jsp:include> YIELDS Fragment "../ContextDemoServlet" was not found at expected path /TestingServlets2/src/main/ ContextDemoServlet

The servlet is configured as: @WebServlet("/ContextDemoServlet")

Any help is greatly appreciated, or simply point me in a direction with some resources to understand this problem. Everything I've read so far indicates that it should work with my configuration, but I'm clearly doing something wrong. I can navigate to the servlet pages within the server as well and they are doing what they need to do...The JSP just can't see it.

Megabytes
  • 1
  • 1
  • Why would you want to include raw java code in your JSP? Include action tag is used for including another resource to the current JSP page. The included resource can be a static page in HTML, JSP page or Servlet. Why are you even trying to include a Servlet? – Scary Wombat Feb 02 '22 at 02:09
  • I agree that it is not best practice, I'm trying to copy what a professor did in a lecture but it just is not working for me and I've attempted to configure it the way he did. The point of the exercise to demonstrate some privative functions. Simply including it as he indicated is not working. I'll email him. Thanks anyway. – Megabytes Feb 02 '22 at 02:18

0 Answers0