Solved

Problem with Struts and JSP with jsp:include statement

Posted on 2004-08-13
2
846 Views
Last Modified: 2013-11-18
We have a J2EE struts-based web application running on Tomcat 3.3, Java JDK 1.3, and Struts 1.1 (we cannot upgrade any of these at this time due to existing customer production environments - I wish we could).  Anyway, we are in the process of cleaning up the JSP's using a multi-pass approach.  In the first pass we are moving the common (i.e. header, footer) source code into separate JSP's.  We are running into a problem with form-based JSP's...

Our login JSP requires user input (obviously) and thus uses a Struts form.  When we add a <jsp:include... statement to include header.jsp we get the following error (trace below):

Error: 500
Location: /providerPortal/index.jsp
Internal Servlet Error:

javax.servlet.ServletException
      at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:460)
      at index_95._jspService(index_95.java:556)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java)
      at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
      at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
      at org.apache.tomcat.core.Handler.service(Handler.java:235)
      at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
      at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
      at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
      at java.lang.Thread.run(Thread.java:479)

Root cause:
javax.servlet.jsp.JspException
      at org.apache.struts.taglib.html.FormTag.initFormBean(FormTag.java:563)
      at org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:520)
      at index_95._jspService(index_95.java:174)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java)
      at org.apache.tomcat.facade.ServletHandler.doService(ServletHandler.java:574)
      at org.apache.tomcat.core.Handler.invoke(Handler.java:322)
      at org.apache.tomcat.core.Handler.service(Handler.java:235)
      at org.apache.tomcat.facade.ServletHandler.service(ServletHandler.java:485)
      at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:917)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
      at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
      at java.lang.Thread.run(Thread.java:479)

The header.jsp source code is irrelevant.  Just adding the <jsp:include... statement causes the problem.  If we change it to include directive "<%@ include file=" it works, but since we also want to use parameters we don't see this as the right solution.  NOTE: JSP pages that do NOT contain a form work fine with the <jsp:include... tag in them.  The relevant code snippets follow:

THE LOGIN.JSP FILE SNIPPET
---------------------------------
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html>
<jsp:include page="header.jsp" flush="true">
</jsp:include>
<html:form
      action="/login"
      method="post"
      focus="username">
                  <table cellpadding="5" bgcolor="#C9D1D6">
                        <tr>
                              <td valign="baseline">
                              <bean:message key="prompt.username" />
                              </td>
                              <td>
                              <img src="images/spacer.gif" width="12">
                              </td>
                              <td valign="baseline">
...

STRUTS-CONFIG.XML SNIPPET
------------------------------------
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
      "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
      "http://jakarta.apache.org/struts/dtd/struts-config_1_1.dtd">
      
<struts-config>
      
      <!--//====================== FORM BEANS ========================//-->
      <form-beans>
            <form-bean      name="LoginForm"
                              type="com.portal.struts.LoginForm" />
            <form-bean      name="searchForm"
                              type="com.portal.struts.SearchForm" />
      </form-beans>

      <!--//====================== GLOBAL FORWARDS ========================//-->
      <global-forwards>
            <forward name="mainpage" path="/index.jsp" />
      </global-forwards>
      
      <!--//====================== ACTION MAPPINGS ========================//-->      
      <action-mappings>
            <action path="/login"
                        type="com.portal.struts.LoginAction"
                        name="LoginForm"
                        scope="request"
                        validate="true"
                        input="/index.jsp">
                  <forward name="success" path="/mainmenu.jsp" />
                  <forward name="failure" path="/index.jsp" />
            </action>
            <action path="/displayList"
                        type="com.portal.struts.DisplayListAction"
                        input="/mainmenu.jsp">
                  <forward name="success" path="/displayList.jsp" />
                  <forward name="failure" path="/mainmenu.jsp" />
            </action>
            <action path="/search"
                        type="com.portal.struts.SearchAction"
                        name="searchForm"
                        scope="request"
                        validate="true"
                        input="/searchres.jsp">
                  <forward name="success" path="/searchres.jsp" />
            </action>
            <action path="/downloadFile"
                        type="com.portal.struts.DownloadFileAction"
                        input="/displayList.jsp">
            </action>
      </action-mappings>

      <!--//====================== CONTROLLER ========================//-->
      <controller processorClass="org.apache.struts.action.RequestProcessor" />
      
      <!--//====================== RESOURCES ========================//-->      
      <message-resources parameter="PortalResources" />

      <!--//====================== PLUGINS ========================//-->      
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
          <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
                                                    /WEB-INF/validation.xml"/>
    </plug-in>
      
</struts-config>

Does anyone have an idea what might be going on here, or have any suggestions.  Again, we cannot upgrade our environment at this time.  In the next JSP "pass" we are going to Tiles but we need to get JSP include based solution working first.  If you need to see any more code please let me know.

Thanks in advance!

Environment:
Windows XP Professional, SP1
Tomcat v3.3a
Java JDK 1.3
Struts 1.1
0
Comment
Question by:mbeede
2 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11798062
> The header.jsp source code is irrelevant.  

think it is actually, jsp:include processes the page and includes the output.
0
 
LVL 3

Accepted Solution

by:
sbockelman earned 500 total points
ID: 11801374
If the included jsp uses form bean or form bean properties, it would be a problem, because the header.jsp is not a struts action, nor have you accessed via a forward from an action.  If the jsp tries to use the form bean, it won't be there and thus the exception.  Try changing bean scope to session and changing the include to include a struts action that forwards to header.jsp; you also have to set the name parameter of that action to the same form bean.
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
installing and using WTP plugin eclipse MARS 3 117
Coova-Chilli can't work with URL using HTTPS! 3 219
Windows Tool to Build Android and iOS App 3 78
jsp login check 12 32
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question