Greetings! I have been learning about Struts and decided it was the Right Thing (tm) to use for web application development. I am using Struts 0.5 on Tomcat 3.1 on Linux 2.2.17. The servlet engine and struts are installed and work fine. Basically, I am writing a test app as a prelude to real development. I wanted simply to get data from a database, display it in a form and modify it. So, I have successfully created an OraclePooledConnection and added it the the servlet context. I can grab a connection and instantiate a modeled class from the database in the Action for the form to be populated. Again, that works fine. Where I run into difficulties is when I forward to the form to be populated inside the Action. To illustrate, I have attached my code and included the exception I am getting.
<!-- $Id: action.xml,v 1.3 2000/11/04 00:23:38 leeb Exp $ --> <!-- Action Mappings for STRUTS based Virtual Trade Show application--> <action-mappings> <!-- Global Forward Declarations --> <forward name="index" path="/index.jsp"/> <!-- edit test bean form --> <action path="/editTestForm" actionClass="com.piperstudiosinc.vts.EditTestFormAction" formAttribute="testForm" formClass="com.piperstudiosinc.vts.TestForm"> <forward name="success" path="/test.jsp"/> </action> <!-- save test bean form --> <action path="/saveTestForm" actionClass="com.piperstudiosinc.vts.SaveTestFormAction" formAttribute="testForm" formClass="com.piperstudiosinc.vts.TestForm" inputForm="/test.jsp"> <forward name="success" path="/test.jsp"/> </action> </action-mappings>
<!-- $Id: index.jsp,v 1.3 2000/11/03 01:14:20 leeb Exp $ --> <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="struts" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="struts" %> <html> <head> <title><struts:message key="index.title"/></title> </head> <body bgcolor="white"> <struts:ifAttributeMissing name="database" scope="application"> <font color="red"> ERROR: User database not loaded -- check servlet container logs for error messages. </font> <hr> </struts:ifAttributeMissing> <struts:ifAttributeMissing name="org.apache.struts.action.MESSAGE" scope="application"> <font color="red"> ERROR: Application resources not loaded -- check servlet container logs for error messages. </font> </struts:ifAttributeMissing> <h3><struts:message key="index.heading"/></h3> <struts:link href="editTestForm.do">BEAN TEST FORM</struts:link> </body> </html>
<!-- $Id: test.jsp,v 1.1 2000/11/04 00:25:02 leeb Exp $ --> <%@ page language="java" %> <%@ taglib uri="/WEB-INF/struts.tld" prefix="struts" %> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="struts" %> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="struts" %> <html> <head> <title><struts:message key="index.title"/></title> </head> <body bgcolor="white"> <h3><struts:message key="index.heading"/></h3> <struts:errors/> <struts:form action="saveTestForm.do" name="testForm" type="com.piperstudiosinc.vts.TestForm"/> <table border="0" width="100%"> <tr> <th> <struts:message key="prompt.first"/> </th> <td> <struts:text property="first" size="16"/> </td> </tr> <tr> <th> <struts:message key="prompt.last"/> </th> <td> <struts:password property="last" size="16"/> </td> </tr> <tr> <td> <struts:submit> <struts:message key="button.submit"/> </struts:submit> </td> <td> <struts:reset> <struts:message key="button.reset"/> </struts:reset> </td> </tr> </table> </struts:form> </body> </html>
// $Id: EditTestFormAction.java,v 1.1 2000/11/04 00:25:02 leeb Exp $ package com.piperstudiosinc.vts; import java.io.*; import java.util.*; import java.sql.*; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionBase; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionServlet; import org.apache.struts.util.ErrorMessages; import org.apache.struts.util.MessageResources; import oracle.jdbc.driver.*; import oracle.jdbc.pool.*; /** * Implementation of <strong>Action</strong> * */ public final class EditTestFormAction extends ActionBase { // --- Public Methods /** * Process the specified HTTP request, and create the corresponding HTTP * response (or forward to another web component that will create it). * Return an <code>ActionForward</code> instance describing where and how * control should be forwarded, or <code>null</code> if the response has * already been completed. * * @param servlet The ActionServlet making this request * @param mapping The ActionMapping used to select this instance * @param actionForm The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception occurs */ public ActionForward perform(ActionServlet servlet, ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Extract attributes we will need Locale locale = getLocale(request); MessageResources messages = getResources(servlet); HttpSession session = request.getSession(); VTSTest vtstest = null; Connection conn = null; OraclePooledConnection oraclePool = (OraclePooledConnection) servlet.getServletContext().getAttribute(VTSConstants.DATABASE_KEY); // test for the database connection int id = 0; try { conn = oraclePool.getConnection(); } catch (Exception e) { servlet.log("Problem getting connection from pool " + e.getMessage()); } vtstest = new VTSTest(conn, id, servlet); // Populate the user registration form if (form == null) { form = new TestForm(); session.setAttribute(mapping.getFormAttribute(), form); } servlet.log(mapping.getFormAttribute()); if (form == null) { form = new TestForm(); session.setAttribute(mapping.getFormAttribute(), form); } TestForm testform = (TestForm) form; testform.setFirst(vtstest.getFirst()); testform.setLast(vtstest.getLast()); /* HttpSession session = request.getSession(); session.setAttribute(Constants.USER_KEY, user); if (servlet.getDebug() >= 1) servlet.log("LogonAction: User '" + user.getUsername() + "' logged on in session " + session.getId()); */ // close the connection try { conn.close(); } catch (Exception e) { servlet.log("Problem returing connection to pool " + e.getMessage()); } // Forward control to the specified success URI return (mapping.findForward("success")); } }
// $Id: TestForm.java,v 1.1 2000/11/04 00:25:02 leeb Exp $ package com.piperstudiosinc.vts; import java.util.Vector; import org.apache.struts.action.ValidatingActionForm; /** * TestForm java bean, for testing struts */ public final class TestForm implements ValidatingActionForm { // --- Instance Variables /** * The first name. */ private String first= null; /** * The last name. */ private String last = null; // --- Properties /** * Get the first name. */ public String getFirst() { return (this.first); } /** * Set the first name. */ public void setFirst(String first) { if (first == null) this.first = ""; else this.first = first; } /** * Get the last name. */ public String getLast() { return (this.last); } /** * Set the last name. */ public void setLast(String last) { if (last == null) this.last = ""; else this.last = last; } // --- Public Methods /** * Validate the properties of this form bean, and return an array of * message keys for any errors we encounter. */ public String[] validate() { Vector errors = new Vector(); if ((first == null) || (first.length() < 1)) errors.addElement("error.first.required"); if ((last == null) || (last.length() < 1)) errors.addElement("error.last.required"); String[] results = null; if (errors.size() > 0) { results = new String[errors.size()]; for (int i = 0; i < results.length; i++) results[i] = (String) errors.elementAt(i); } return results; } }
Internal Servlet Error: javax.servlet.ServletException: Cannot find bean under name org.apache.struts.taglib.BEAN at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:386) at _0002ftest_0002ejsptest_jsp_64._jspService(_0002ftest_0002ejsptest_jsp_64.java:421) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:174) at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261) at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503) at org.apache.tomcat.core.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:163) at org.apache.struts.action.ActionServlet.processActionInstance(ActionServlet.java:803) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:702) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:314) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559) at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160) at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338) at java.lang.Thread.run(Thread.java:475) Root cause: javax.servlet.jsp.JspException: Cannot find bean under name org.apache.struts.taglib.BEAN at org.apache.struts.taglib.BaseFieldTag.doStartTag(BaseFieldTag.java:174) at _0002ftest_0002ejsptest_jsp_64._jspService(_0002ftest_0002ejsptest_jsp_64.java:204) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:126) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.jasper.runtime.JspServlet$JspServletWrapper.service(JspServlet.java:174) at org.apache.jasper.runtime.JspServlet.serviceJspFile(JspServlet.java:261) at org.apache.jasper.runtime.JspServlet.service(JspServlet.java:369) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503) at org.apache.tomcat.core.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:163) at org.apache.struts.action.ActionServlet.processActionInstance(ActionServlet.java:803) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:702) at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:314) at javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at org.apache.tomcat.core.ServletWrapper.handleRequest(ServletWrapper.java:503) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:559) at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:160) at org.apache.tomcat.service.TcpConnectionThread.run(SimpleTcpEndpoint.java:338) at java.lang.Thread.run(Thread.java:475) -- Lee "Lefty" Burgess <<!>> Manipulate eternity. Power is a symphony: Web Application Developer <<!>> elaborate, enormous, essential. PiperStudiosInc <<!>> Dream the moment with a fiddle in summer [EMAIL PROTECTED] <<!>> and a knife in winter.