I have created two JSP pages (toBeImportedPage.jsp and mainPage.jsp). I need to import the toBeImportedPage.jsp inside the mainPage.jsp. To achieve this I have used JSTL tag libraries (<%@ taglib uri=”http://java.sun.com/jstl/core” prefix=”c”%>) in the mainPage.jsp and <c:import> tag to import the jsp. Both JSP pages are in the same folder location.
Find below the code for my mainPage.jsp page –<%@ taglib uri=”http://java.sun.com/jstl/core” prefix=”c”%> <HTML> <HEAD> <TITLE> Main JSP </TITLE> </HEAD> <BODY> <form method=”post” name=”LeadTimeForm” action=”” onSubmit=”return validateLeadTimeForm()”> <c:import url=”/toBeImportedPage.jsp”/> </form> </BODY> </HTML>
You can use any HTML editor to created the above two JSP pages. I have used EditPlus editor. When I tried to execute or run my mainPage.jsp page from the editor, I see the blank page. The toBeImportedPage.jsp page is not imported.
I have cross checked if there may be something wrong in using the JSTL tags in the JSP, but everything was correctly used. But still I’m not able to see my imported JSP.
After struggling for some time, I have found that the JSTL tags will be understood and executed by the JSP compiler only after the JSP is converted into Servlet class. To happen this conversion the JSP pages should be deployed in to any Application Server.
So in my case I have used Jdeveloper and proceeded as listed below –
- Created a Java Project
- Added my two JSP pages.
- Created an WAR or EAR file for the Java Project.
- Deployed the EAR or WAR file into Weblogic Application server.
- Executed the mainPage.jsp page from the Weblogic server.
Hurry !!! Now I can view the imported jsp (toBeImportedPage.jsp) in the main JSP (mainPage.jsp).
So in case if we find any of the tag libraries are not working while executing from the editor, that simply means the JSP pages need to be deployed into an Application Server and need to execute.