0

I have an application which has a jsp file. I need to include another jsp file which is in tomcat properties folder in this jsp file. I tried several methods but everytime I get the error as the file cannot be found.

Jsp in application:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" isErrorPage="false"%>
<%@ page import="java.io.*,java.util.*" %>

<%
String brandFile="/home/tomcat/properties/utransfer/brand/brand_1.jsp";
request.getRequestDispatcher(brandFile).include(request,response);
%>

/home/tomcat/properties/utransfer/brand/brand_1.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>

Hello

</html>

The error I get is :

Caused by: javax.servlet.ServletException: File [&#47;home&#47;tomcat&#47;properties&#47;utransfer&#47;brand&#47;brand_1.jsp] not found
        at org.apache.jasper.servlet.JspServlet.handleMissingResource(JspServlet.java:408)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:375)

In the application jsp I also tried the following:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" isErrorPage="false"%>
<%@ page import="java.io.*,java.util.*" %>

<%!
String brandFile="/home/tomcat/properties/utransfer/brand/brand_1.jsp";
%>

<jsp:include page="<%=brandFile %>" />

Also tried,

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" isErrorPage="false"%>
<%@ page import="java.io.*,java.util.*" %>


<%@ include file="/home/tomcat/properties/utransfer/brand/brand_1.jsp" %>

Also tried,

<%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ page language="java" isErrorPage="false"%>
    <%@ page import="java.io.*,java.util.*" %>


<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>


    <c:import var = "data" url = "/home/tomcat/properties/utransfer/brand/brand_1.jsp"/>
      <c:out value = "${data}"/>

I tried the following code:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" isErrorPage="false"%>
<%@ page import="java.io.*,java.util.*" %>


<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>


<c:import url = "http://serverName/utransfer_static/brand/brand_1.jsp"/>

Getting the following error:

Caused by: java.io.IOException: Server returned HTTP response code: 500 for URL: http://serverName/utransfer_static/brand/brand_1.jsp
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1894)

In browser, if I directly give this URL (http://serverName/utransfer_static/brand/brand_1.jsp), I am getting the contents.

Please advice on what can be done. Thanks.

Divya Rose
  • 227
  • 4
  • 22
  • 1
    Possible duplicate of [How to Include a file outside the application (war) using jsp include](https://stackoverflow.com/questions/828973/how-to-include-a-file-outside-the-application-war-using-jsp-include) – Ori Marko Jul 22 '19 at 08:11
  • The solution mentioned there is to use c:import which I have tried as well. But not working. Everytime, getting the same error. – Divya Rose Jul 23 '19 at 05:22

0 Answers0