Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Problem with Struts and JSP with jsp:include statement

Posted on 2004-08-13
2
Medium Priority
?
900 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 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

885 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