struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rod McChesney <r...@expressaction.com>
Subject Re: problem with Weblogic 5.1
Date Fri, 01 Sep 2000 19:29:51 GMT
As a side issue, I wrote a little custom tag to work around the
broken load-on-startup tag. It's better than nothing...

The TLD <tag>entry looks something like
  <tag>
    <name>init</name>
    <tagclass>your.package.InitTag</tagclass>
    <bodycontent>empty</bodycontent>
    <info>
      Initializes the Struts ActionServlet as a workaround for
      WebLogic 5.1's problem with load-on-startup.
    </info>
  </tag>

You add this to every page:

<%@ taglib uri="/WEB-INF/your-app.tld" prefix="your-prefix" %>
<your-prefix:init />

The code assumes the action servlet is mapped to *.do, btw.
You can call a real action instead of "test.do" or create a dummy one.

----------------------------------------------------------
package your.package;

import java.net.URL;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.struts.action.Action;


/**
 * Initializer custom tag.
 */
public class InitTag extends TagSupport {

    /**
     * Make sure the Struts ActionServlet is initialized. This is a
     * workaround for WebLogic 5.1's inability to use the 
     * web.xml load-on-startup tag.
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doStartTag() throws JspException {
	try {
	    ServletContext ctx = pageContext.getServletContext();
	    if (ctx.getAttribute(Action.MESSAGES_KEY) == null) {
		ServletRequest req = pageContext.getRequest();
		String scheme = req.getScheme();
		String uri = ((HttpServletRequest)req).getRequestURI();
		int lastSlash = uri.lastIndexOf("/");
		if (lastSlash >= 0) {
		    String appPrefix = uri.substring(0, lastSlash);
		    URL url = new URL(req.getScheme() + "://" + 
				      req.getServerName() + ":" + 
				      req.getServerPort() + 
				      appPrefix + "/test.do");
		    ctx.log("Loading action servlet with " + url);
		    url.openConnection().getContent();
		}
	    }
	} catch (Throwable t) {
	    // Don't care about problems
	}
	return (SKIP_BODY);
    }
}

Mime
View raw message