David ,

     Echo is good...as it turned out this line was returning null,

      String userName = ((LogonForm) form).getUsername();

I'm new to java and Tomcat/Struts so I'm strugglig with where to put the users info once they have successfully logged on.(Logon is just a query to a database to find unername and password) I guess the LogonForm object is inaccessable once the LogonAction finishes up.

I thought setting attributes was best, is that the case? Jim barrows on this list suggested I do this,

 String x =  request.getRemoteUser();

...but it also returns null from an ActionForward


-Jim


From: "David G. Friedman" <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Subject: RE: Mapping issue
Date: Thu, 16 Dec 2004 19:59:33 -0500

Jim,

Since your JSP thinks something is null, have you tried putting something
like the below code in your RetrieveFormAction.execute() method before you
do your request.setAttribute(...) call?

if ( result == null ) {
        System.out.println("Result set is NULL!");
} else {
        System.out.println("Result has " + result.size() + " items.");
}

OR, in your JSP, have you added similar code to the below?

<%
  ArrayList forms = (ArrayList)request.getAttribute("forms");
  if ( forms == null ) {
        out.println("I am a null form, help!");
  } else {
        out.println("Forms exists, let's see the data.<br />");
     Iterator it = forms.iterator();

     while(it.hasNext()) {
      out.print("<br>try " + it.next());
     }
  }
%>

I'm big on echo printing where debugging null pointers are concerned. :)

Regards,
David

-----Original Message-----
From: Jim Douglas [mailto:[EMAIL PROTECTED]
Sent: Wednesday, December 15, 2004 11:26 PM
To: [EMAIL PROTECTED]
Subject: RE: Mapping issue


David,

Yes, struts-conf is in WEB-INF,

Here's the application error log, apparently it's finding the for.jsp before
crashing,


DEBUG - insert page='/portal/forms.jsp'.
DEBUG - servletPath=/portal/forms.jsp, pathInfo=null, queryString=null,
name=null
DEBUG -  Path Based Include
INFO - default: DefaultServlet.serveResource:  Serving resource
'/images/id_nav_outside.gif' headers and data
INFO - default: DefaultServlet.serveResource:  Serving resource
'/images/id_nav_bkgnd.gif' headers and data
ERROR - Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
        at
org.apache.jsp.portal.forms_jsp._jspService(org.apache.jsp.portal.forms_jsp:
52)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3
25)


This is forms.jsp,

<%@ page import="java.util.*" %>

<html>
<body>
<h1 align="center">Forms Listing</h1>
<p>

<%
  ArrayList forms = (ArrayList)request.getAttribute("forms");
  Iterator it = forms.iterator();

  while(it.hasNext()) {
    out.print("<br>try " + it.next());
  }

%>
</body>
</html>


...and this is the code that sets the "forms attribute,

public final class RetrieveFormAction extends Action {

    private final static Logger log =
Logger.getLogger(RetrieveFormAction.class);
    String sTemp ="";

    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form, HttpServletRequest
request,
                                 HttpServletResponse response)
                                 //throws IOException, ServletException {
                                 throws Exception {
        ArrayList forms = new ArrayList();

        String userName = ((LogonForm) form).getUsername();

        DataSource dataSource = getDataSource(request, "userDB");
        Connection conn = dataSource.getConnection();
        Statement stmt = conn.createStatement();

        String query = "SELECT * FROM users";

        log.info("query = " + query);
        ResultSet rs = stmt.executeQuery(query);

        Boolean validate = false;
        while (rs.next())       {
                sTemp = rs.getString(1);
                forms.add(sTemp);        }
        rs.close();
        rs = null;

        ArrayList result = forms;
        request.setAttribute("forms", result);
        return mapping.findForward("show_forms");

  }
}

Thanks,
Jim

>From: "David G. Friedman" <[EMAIL PROTECTED]>
>Reply-To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
>Subject: RE: Mapping issue
>Date: Wed, 15 Dec 2004 19:31:14 -0500
>
>Have you checked your application server's log files to see if there were
>any Struts startup errors?  Where are you putting the "struts-conf" file?
>Are you putting it in the file "/WEB-INF/struts-config.xml"?
>
>Regards,
>David
>
>-----Original Message-----
>From: Jim Douglas [mailto:[EMAIL PROTECTED]
>Sent: Wednesday, December 15, 2004 7:17 PM
>To: [EMAIL PROTECTED]
>Subject: Mapping issue
>
>
>To all,
>
>This is my error message in the browser,
>
>javax.servlet.ServletException: Cannot retrieve mapping for action
>/SelectUser
>
>The class files are in the right place.  This is struts-conf,
>
><form-beans>
>     <form-bean name="ReturnStudentForms"
>                type="app.model.FormsSelect" />
>   </form-beans>
>
><action-mappings>
>
>   <action-mappings>
>     <action path="/SelectUser"
>        type="app.web.RetrieveFormAction"
>        name="ReturnStudentForms" scope="request"
>        validate="true" input="/portal/user.jsp">
>    <forward name="show_forms"
>             path="/portal/forms.jsp" />
>     </action>
>   </action-mappings>
>
>
>Thanks,
>Jim
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to