?
Solved

Taglibs increasing the size of JSP.

Posted on 2003-03-06
15
Medium Priority
?
1,018 Views
Last Modified: 2013-11-24
Hi,
For my internaionalization project i have used taglibs for conversion of property file keys.

Since there is lot of data to be converted, i have to use lot of tags. Excess use of Tag (50-60 in number) has increased the size of my jsp when its parsed to java. And i am getting java.lang.VerifyError: Illegal Jump or branch start

How can i use my tag class effectively so that its not overhead to the JSP
0
Comment
Question by:agsingh
[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
  • 9
  • 4
  • 2
15 Comments
 

Author Comment

by:agsingh
ID: 8084153
Here is my Tag Class
========================
import java.io.IOException;

import java.text.MessageFormat;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.ServletContext;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.BodyTagSupport;


public class MessageTag extends BodyTagSupport
{
    // instance variables used during processing
    private String               _key = null;
    private String               _value = null;
    private ResourceBundle       _bundle = null;
    private boolean              _debug = false;

    // these are reused for each message tag; luckily tags are thread-safe
    private MessageFormat  _messageFormat = new MessageFormat("");
    private List           _arguments = new ArrayList();

    /**
     *  sets the key to use when looking up the value in the bundle
     */
    public final void setKey(String key)
    {
        _key = key;
    }

    /**
     *  sets the bundle to an actual ResourceBundle object<br>
     *  defined on the page by the i18n:bundle tag
     */
    public final void setBundle(ResourceBundle aBundle)
    {
        _bundle = aBundle;
    }

    /**
     *  @return the bundle to use
     */
    private ResourceBundle getBundle() throws JspException
    {
            if(_bundle == null)
            {
                  BundleTag bundleTag = (BundleTag)this.findAncestorWithClass(this,BundleTag.class);
                  if (bundleTag != null)
                  {
                        System.out.println("from bundle if");
                        return bundleTag.getBundle();
            }
            }
        return _bundle;
    }

    /**
     * Turn debugging log messages on or off
     */
    public final void setDebug(boolean value)
    {
        _debug = value;
    }

    /**
     *  clears the argument list so that sub tags can call addArgument
     *  clears out any previous key and value in case key is not provided,
     *  or the value is null
     */
    public final void release()
    {
        super.release();
        _key = null;
        _value = null;
        _bundle = null;
    }


      /**
       * To Print debug statements when _debug is true
       */
      private void debugLog(String message)
      {
            if(_debug)
            {
                        ServletContext sc = pageContext.getServletContext();
                        sc.log(message);
            }
      }


  /**
   *  locates the bundle and gets the value
   */
  public final int doStartTag() throws JspException
    {
       // Reset value for resource bundle key
       _value = null;

       // ensure we have a key
        if ( _key == null ) {
            throw new JspTagException("i18n:message tag requires a key attribute.");
        }

        ResourceBundle bundle = this.getBundle();
        if ( bundle == null ) {
            throw new JspTagException(
                "i18n:message tag, no bundle available for use.");
        }


        // see if the bundle has a value, if not, we default to the tag contents
        try {
            _value = bundle.getString(_key);
            debugLog("i18n:message tag: template for " + _key + " is: " + _value);
        } catch (java.util.MissingResourceException e) {
            ServletContext sc = pageContext.getServletContext();
            sc.log("i18n:message tag, value not found for key:" + _key);
        }

        return EVAL_BODY_TAG;
    }

    /**
     *  Performs the proper runtime substitution. If an id attribute was
     *  specified, then it is assumed that this tag is merely defining a
     *  string variable; otherwise output is provided.
     */
    public final int doEndTag() throws JspException
    {
        try {
            // if the value is null, use the body content
            if ( _value == null ) {
                _value = bodyContent.getString();
                bodyContent.clear();
            }
                  // print the value to the JspWriter
                  this.pageContext.getOut().print(_value);

        } catch (java.io.IOException e)
        {
            throw new JspTagException("i18n:message tag IO Error: " + e.getMessage());
        }

        // only process the body once
        return EVAL_PAGE;
    }

}
0
 

Author Comment

by:agsingh
ID: 8084283
Here is my Tag Class
========================
import java.io.IOException;

import java.text.MessageFormat;

import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.ServletContext;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.BodyTagSupport;


public class MessageTag extends BodyTagSupport
{
    // instance variables used during processing
    private String               _key = null;
    private String               _value = null;
    private ResourceBundle       _bundle = null;
    private boolean              _debug = false;

    // these are reused for each message tag; luckily tags are thread-safe
    private MessageFormat  _messageFormat = new MessageFormat("");
    private List           _arguments = new ArrayList();

    /**
     *  sets the key to use when looking up the value in the bundle
     */
    public final void setKey(String key)
    {
        _key = key;
    }

    /**
     *  sets the bundle to an actual ResourceBundle object<br>
     *  defined on the page by the i18n:bundle tag
     */
    public final void setBundle(ResourceBundle aBundle)
    {
        _bundle = aBundle;
    }

    /**
     *  @return the bundle to use
     */
    private ResourceBundle getBundle() throws JspException
    {
            if(_bundle == null)
            {
                  BundleTag bundleTag = (BundleTag)this.findAncestorWithClass(this,BundleTag.class);
                  if (bundleTag != null)
                  {
                        System.out.println("from bundle if");
                        return bundleTag.getBundle();
            }
            }
        return _bundle;
    }

    /**
     * Turn debugging log messages on or off
     */
    public final void setDebug(boolean value)
    {
        _debug = value;
    }

    /**
     *  clears the argument list so that sub tags can call addArgument
     *  clears out any previous key and value in case key is not provided,
     *  or the value is null
     */
    public final void release()
    {
        super.release();
        _key = null;
        _value = null;
        _bundle = null;
    }


      /**
       * To Print debug statements when _debug is true
       */
      private void debugLog(String message)
      {
            if(_debug)
            {
                        ServletContext sc = pageContext.getServletContext();
                        sc.log(message);
            }
      }


  /**
   *  locates the bundle and gets the value
   */
  public final int doStartTag() throws JspException
    {
       // Reset value for resource bundle key
       _value = null;

       // ensure we have a key
        if ( _key == null ) {
            throw new JspTagException("i18n:message tag requires a key attribute.");
        }

        ResourceBundle bundle = this.getBundle();
        if ( bundle == null ) {
            throw new JspTagException(
                "i18n:message tag, no bundle available for use.");
        }


        // see if the bundle has a value, if not, we default to the tag contents
        try {
            _value = bundle.getString(_key);
            debugLog("i18n:message tag: template for " + _key + " is: " + _value);
        } catch (java.util.MissingResourceException e) {
            ServletContext sc = pageContext.getServletContext();
            sc.log("i18n:message tag, value not found for key:" + _key);
        }

        return EVAL_BODY_TAG;
    }

    /**
     *  Performs the proper runtime substitution. If an id attribute was
     *  specified, then it is assumed that this tag is merely defining a
     *  string variable; otherwise output is provided.
     */
    public final int doEndTag() throws JspException
    {
        try {
            // if the value is null, use the body content
            if ( _value == null ) {
                _value = bodyContent.getString();
                bodyContent.clear();
            }
                  // print the value to the JspWriter
                  this.pageContext.getOut().print(_value);

        } catch (java.io.IOException e)
        {
            throw new JspTagException("i18n:message tag IO Error: " + e.getMessage());
        }

        // only process the body once
        return EVAL_PAGE;
    }

}
0
 
LVL 92

Expert Comment

by:objects
ID: 8084427
what does your jsp look like?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:agsingh
ID: 8085203
pasting a portion of my JSP ..if it help
==========================================

<span id="alert"><center><font size=4 color="red">
<%if(msg!=null && !msg.equals("")) { %>
<i18n:message key='<%="tops.text." + ((String)(cc_abObj.getParams("uc15ErrMsg")))%>' debug="true" ></i18n:message><br>
 <%}%>

<%if(msg1!=null && !msg1.equals("")) { %>
<i18n:message key='<%="tops.text." + ((String)(cc_abObj.getParams("SuccMsg")))%>' debug="true" ></i18n:message>
 <i18n:message key='<%="tops.listbox." + ((String)vecCollectShift.get(vecCollectShift.indexOf(strShiftName)+1))%>' debug="true" ></i18n:message>
 <i18n:message key='tops.text.Successfully' debug="true" ></i18n:message>
<!--%=(cc_abObj.getParams("excludeDays"))%-->
 <i18n:message key='tops.text.From' debug="true" ></i18n:message>  <i18n:formatDate value='<%=((String)(cc_abObj.getParams("startDate")))%>' />
 <i18n:message key='tops.text.To' debug="true" ></i18n:message>  <i18n:formatDate value='<%=((String)(cc_abObj.getParams("endDate")))%>' /><br>
 <%}%>

<%if(msg2!=null && !msg2.equals("")) {
     out.println(msg2+"<br>");
}%>

</font></center></span>

<table id="tableRow" border="1" cellspacing="2" cellpadding="2" align="center">
<tr>
<td><b><i18n:message key="tops.text.SupervisorName" debug="true" ></i18n:message></b></td>
<td>
<select multiple  size="3"  name="strlSupervisor">
<option value = "ALL"><i18n:message key="tops.listbox.SelectAll" debug="true" ></i18n:message></option>
     <%
     if(vecSupverisorList != null)
     {
               for(int i=0;i<vecSupverisorList.size();i++)
                    {
                              strEmpNo=(String)vecSupverisorList.elementAt(i);
                              strEmpName=(String)vecSupverisorList.elementAt(++i);
               %>
               <option value="<%=strEmpNo%>"

               <%
                         if(strlSupervisor != null)
                         {
                              for(int k=0;k<strlSupervisor.length;k++)
                              {
                                   if(strEmpNo.equalsIgnoreCase(strlSupervisor[k]))
                                   {
                                        out.println("selected");
                                   }
                              }
                         }
               %>>
               <%=strEmpName%></option>
               <%
                    }
               }
               %>
</select>
</td>
<td>
<input type="button" id="topsButton" name="collectEmp" value="<i18n:message key="tops.button.GetEmployee" debug="true" >Get Employees</i18n:message>" onClick="callSuperVisor(this.form)";>
</td>
</tr>
</table>

<%
Vector vecWorkerList = (Vector)cc_abObj.getObject("vecWorkerList");
if(vecWorkerList != null)
{
if(vecWorkerList.size() != 0)
{
%>
<table id="tableRow" border="1" cellspacing="2" cellpadding="2" align="center">
<tr>
          <td align="left" >
          <table id="tableRow" border="1" cellspacing="2" cellpadding="2" align="center">
          <tr valign = "top">
          <td valign = "top"><b><i18n:message key="tops.text.EmployeeNameNumber" debug="true" >Employee Name/Number</i18n:message></b></td>
          </tr>
====================================
0
 
LVL 92

Expert Comment

by:objects
ID: 8085296
Have a look at the generated Java to see what is causing the exception.
0
 

Accepted Solution

by:
doddjames earned 600 total points
ID: 8087516

Hey,

If your current approach is giving you too much overhead, then what about

<i18n:bundle id="myBundle"/>

<%=myBundle.getString( "myKey" )%>
<%=myBundle.getString( "myOtherKey" )%>

You will need to know about TEI classes for you to write a Tag that will put the bundle in the PageContext so the JSP can use it.

Incidentally, in the past I have found that containers implements Tag re-use and lifecycles differently, so check what yours is doing.  If it calls release() after every invocation then your tag is hugely expensive.  If it doesn't recycle Tags (and I have seen a container that didn't!) then this is also very expensive for you.

Here's some information on TEI classes:

http://www.orionserver.com/taglibtut/5.html
0
 

Author Comment

by:agsingh
ID: 8088079
as a workaround i am using <%=myBundle.getString( "myKey" )%>... But i am getting error in a very unexpected fashion. Same file which is working fine, if it changed a bit and happen to recompile gives me Verify error.

I am pasting converted java file for tag
+++++++++++++++++++++++++++++++++
release() is called for every invocation, apparently its not recycling
=================================
// begin message custom tag block... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
com.gepower.gees.tops.i18n.MessageTag _com_gepower_gees_tops_i18n_MessageTag_0 = null; //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
/*** declare AT_BEGIN TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
try { // begin instantiate/release try/catch/finally block... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0 = new com.gepower.gees.tops.i18n.MessageTag(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0.setPageContext(pageContext); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0.setParent(_com_gepower_gees_tops_i18n_BundleTag_0); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0.setDebug(Boolean.valueOf(weblogic.utils.StringUtils.valueOf("true")).booleanValue()); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
_com_gepower_gees_tops_i18n_MessageTag_0.setKey(weblogic.utils.StringUtils.valueOf("tops.text.AssignShift")); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
int _int_1 = _com_gepower_gees_tops_i18n_MessageTag_0.doStartTag(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
if (_int_1 == Tag.EVAL_BODY_INCLUDE) { //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    throw new JspTagException("Since tag class com.gepower.gees.tops.i18n.MessageTag implements BodyTag, it cannot return Tag.EVAL_BODY_INCLUDE"); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
/*** sync AT_BEGIN TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
if (_int_1 != Tag.SKIP_BODY) { // begin !SKIP_BODY... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    if (_int_1 != Tag.EVAL_BODY_INCLUDE) { //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      out = pageContext.pushBody(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      _com_gepower_gees_tops_i18n_MessageTag_0.setBodyContent((BodyContent)out); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    } //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    try { // begin pushBody try/finally  //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      _com_gepower_gees_tops_i18n_MessageTag_0.doInitBody(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      do { //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
          /*** declare & sync NESTED TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
          //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
          out.print("Assign Shift");
          //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      } while (_com_gepower_gees_tops_i18n_MessageTag_0.doAfterBody() == BodyTag.EVAL_BODY_TAG); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    } finally { // end pushBody try/finally //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      if (_int_1 != Tag.EVAL_BODY_INCLUDE) //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
      out = pageContext.popBody(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
    } //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} // end !SKIP_BODY //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
if (_com_gepower_gees_tops_i18n_MessageTag_0.doEndTag() == Tag.SKIP_PAGE) return; //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} catch (java.lang.Exception _java_lang_Exception_0) { // instantiate/release try/catch/finally //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
throw new ServletException("runtime failure in custom tag 'message'", _java_lang_Exception_0); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} finally { // instantiate/release try/catch/finally block... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
if (_com_gepower_gees_tops_i18n_MessageTag_0 != null) _com_gepower_gees_tops_i18n_MessageTag_0.release(); //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
} //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
//end message custom.... //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
/*** declare & sync AT_END TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
/*** sync AT_BEGIN TagExtra Vars here ***/ //[ /tops3/tnl/jsp/tops3AssignShift.jsp; Line: 69]
0
 

Author Comment

by:agsingh
ID: 8088082
I m using weblogic 510 SP 8
0
 

Expert Comment

by:doddjames
ID: 8088239

The other approach you could use would be to contextualize your i18n lookups, e.g.

<i18n:bundle>
    <i18n:lookup key="myKey"/>
    <i18n:whatever/>
</i18n:bundle>

Your child tags get the loaded bundle from the parent.

As an aside, many people have written i18n libraries, so why not use one?

http://jakarta.apache.org/taglibs/doc/i18n-doc/intro.html
0
 

Author Comment

by:agsingh
ID: 8088279
This is what i am doing..
<%@ taglib uri="tops-i18n.tld" prefix="i18n" %>
<i18n:bundle id="_bundle" debug="true" baseName="properties.tops3.i18n.language">
.
.
.

<i18n:message key="myKey" debug="true" >Assign Shift</i18n:message>
.
.


</i18n:bundle>
message tag is getting bundle from the bundle tag

I am using jakarta taglibs, with minor modification
-Ag
0
 

Expert Comment

by:doddjames
ID: 8088461

Ah, sorry.  I thought you were writing your own.

The verify error must be being caused by a fault in weblogic's jsp compiler.  BEA do make reference to this problem..

"-noTryBlocks

If a JSP file has numerous or deeply nested custom JSP tags and you receive a java.lang.VerifyError exception when compiling, use this flag to allow the JSPs to compile correctly."

According to what I've read on the net, you should be able to configure weblogic.xml to supply this parameter to the compiler:

<jsp-param>
  <param-name>compileFlags</param-name>
  <param-value>"-noTryBlocks"</param-value>
</jsp-param>




0
 

Author Comment

by:agsingh
ID: 8088693
thats a relief..!!
I have not deployed my app as a webapplication so not using web.xml, using weblogic.properties
Any idea how to pass -noTryBlocks through it,
Also can u give me a ref where u found this fault in weblogic JSP compiler.

Thanks,
0
 

Expert Comment

by:doddjames
ID: 8088910

Hmm.. That option won't work with a WL5.1 jspc (need WL6.0+).  They didn't address the problem with a compiler option until 6.0.

http://www.weblogic.com/docs51/classdocs/API_jsp.html#compiler
http://edocs.bea.com/wls/docs60/jsp/reference.html#57794

You could also try finding a different jsp compiler and configuring WL to use that instead.  Maybe it'll produce more efficient code.

The root problem seems to be that your generated class files are too big.  The elimination of all the try/catch blocks generated by the jsp compiler would help (if you could do it with WL5.1, which you don't seem to be able to :-( ), but failing that you're just going to have to slim down or refactor your JSP into more manageable chunks and <jsp:include/> bits and bobs here and there.

http://www.caucho.com/support/resin-interest/0005/0251.html

0
 

Author Comment

by:agsingh
ID: 8093107
getting lots of problems when compiling using java weblogic.jspc
[jspc] parsed .\tnl\jsp\calledbackreport.jsp in 661 ms.
[jspc] generated java file c:\abhi\jsp_servlet\__46_\_tnl\_jsp\_calledbackreport.java, invoking java compiler:
Exec failed .. exiting

:(
0
 

Author Comment

by:agsingh
ID: 8152439
didnt get my answer..perhaps it was a wrong implementation of Taglibs.
There is lot behind the scenes. Thanks James for clearing out some of them..!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month12 days, 17 hours left to enroll

777 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