Solved

Problem with Struts and JSP with jsp:include statement

Posted on 2004-08-13
2
833 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
Comment Utility
> 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to count occurrences of each item in an array.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now