?
Solved

Problem with Struts and JSP with jsp:include statement

Posted on 2004-08-13
2
Medium Priority
?
888 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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ā€¦
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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).

719 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