Solved

Problem with Struts and JSP with jsp:include statement

Posted on 2004-08-13
2
842 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 Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
css border raidius issue 7 81
maven project jars 7 50
two submit buttons one form 15 75
Field that has HTML displays the code instead of the text in html 16 64
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

22 Experts available now in Live!

Get 1:1 Help Now