Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2008
    Location
    Bismarck, ND, USA
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question What is the correct method for instantiating a bean and accessing from a JSP servlet?

    Hoookay. I'm having an issue with [I believe] instantiating a bean as well as properly defining methods and variables within this bean package/class correctly. I am attempting to access a method of package myBeans; -- specifically -- public int parseSLData(void);, and 2 arrays (a one dimensional and a two dimensional array of integers) from within a JSP page's embedded scriptlet. I will be the first to admit that I do not properly understand the concepts of instantiation and I'm a little hazy on public vs. static (think I've got the private concept down pretty well) when defining variables and other object members. I will attempt to post all of the relevant information about the issue that I'm having here; if there's something else that is needed in order to understand this issue, please let me know I'll be happy to post anything that I might've left out the first time around.

    I would be very happy if anyone can take a minute to help me understand these concepts a little bit better and/or direct me to some well written resources on these concepts. Most of the ones that I've been able to turn up are a bit rough for me to understand. I've had to dive into java a lot quicker than I would like due to a project that I've been given, instead of having proper time to learn the language fully (as well as the Bean programming interface), and I'm suffering a bit because of it. Also, now that I review the source a little bit more, it seems to me that I may be making mistakes in attempting to set some of the bean properties via JSP's <jsp:setProperty ... /> tags.

    -=-=-=-=-
    from <project_home>/src/java/myBeans/ServiceLogBean.java:

    Code:
    package myBeans;
    
    include ...;
    
    public class ServiceLogBean {
      private String, Date, & int variables ...;
    
      private static int constants ...;
    
      int aList[CONSTANT1];
      int bList[CONSTANT2][];
    
      public void setMethods(int blah) {
    	this.blah = blah;
      }  //multiple instances of this, of course
    
      private ResultSet pollPunches() {
    	...
      	return ResultSet myResults;
      }
    
      private int fetchActivities(ResultSet woo) {
    	...
    	return myCode;
      }
    
      public int parseSLData() {
    	ResultSet rs = null;   //not private, this is instance
    
    	rs = pollPunches();
    
    	if (rs == null) {
    	    //something went wrong in pollPunches()
    	    return -1;
    	}
    
    	if (fetchActivities(rs) == -1) {
    	    //something went wrong in fetchActivities()
    	    return -2;
    	}
    
    	return 0;
      }
    }
    -=-=-=-=-
    this bean is utilized in the following relevant parts of [an otherwise error free] JSP file <project_home/web/genECMServiceLog.jsp:

    Code:
     <c:when test="${param.process == 'Generate Report'}">
    
       <jsp:useBean id="serviceLogBean"
    		class="myBeans.ServiceLogBean"
    		scope="page" />
       <jsp:setProperty name="serviceLogBean"
    		    property="patient"
    		    value="${param.patId}" />
       <jsp:setProperty name="serviceLogBean"
    		    property="location"
    		    value="${param.loc}" />
       <jsp:setProperty name="serviceLogBean"
    		    property="mon"
    		    value="${param.mon}" />
       <jsp:setProperty name="serviceLogBean"
    		    property="yr"
    		    value="${param.yr}" />
    
       <%
    	int dayCntr, actCntr = 0;
    	ServiceLogBean myServiceLogBean = ServiceLogBean;
    
    	switch (myServiceLogBean.parseSLData()) { //execute Bean logic
    
    	...
    	}
       %>
    -=-=-=-=-
    this produces the following error with 'ant':

    Dec 22, 2008 2:04:32 PM org.apache.catalina.core.ApplicationDispatcher invoke
    SEVERE: Servlet.service() for servlet jsp threw exception
    org.apache.jasper.JasperException: Unable to compile class for JSP:

    An error occurred at line: 93 in the jsp file: /genECMServiceLog.jsp
    ServiceLogBean cannot be resolved to a type
    90:
    91: <%
    92: int dayCntr, actCntr = 0;
    93: ServiceLogBean myServiceLogBean = new ServiceLogBean;
    94:
    95: switch (myServiceLogBean.parseSLData()) { //execute Bean logic
    96: case -1:


    An error occurred at line: 93 in the jsp file: /genECMServiceLog.jsp
    Syntax error on token "new", delete this token
    90:
    91: <%
    92: int dayCntr, actCntr = 0;
    93: ServiceLogBean myServiceLogBean = new ServiceLogBean;
    94:
    95: switch (myServiceLogBean.parseSLData()) { //execute Bean logic
    96: case -1:


    An error occurred at line: 93 in the jsp file: /genECMServiceLog.jsp
    ServiceLogBean cannot be resolved
    90:
    91: <%
    92: int dayCntr, actCntr = 0;
    93: ServiceLogBean myServiceLogBean = new ServiceLogBean;
    94:
    95: switch (myServiceLogBean.parseSLData()) { //execute Bean logic
    96: case -1:


    -=-=-=-=-
    I've played around with using 'myBeans.ServiceLogBean' in place of ServiceLogBean in the JSP scriptlet (2nd cut 'n paste), as well as removing 'new', and each of those just brings up other errors about the different integer arrays not being visible, along with different issues with the original declaration of myServiceLogBean.

    I've been around the rosie quite a few times with this. I'm really grateful for any assistance that anybody can lend on this issue, and I'll be looking for anything applicable online and in my ORA text in the meantime.

    TIA

    -Damon

    -=-=-=-
    Damon Getsman
    ITRx - a division of Applied Medical, Inc.
    http://www.ITRx-ND.com/
    -=-=-=-

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I can't say that I know JSP specifically but- put parentheses around your ServiceLogBean declaration:
    ServiceLogBean myServiceLogBean = new ServiceLogBean();

    See where that gets you for compilation.



  • Users who have thanked Brandoe85 for this post:

    damo.gets (12-23-2008)

  • #3
    New Coder
    Join Date
    Aug 2008
    Location
    Bismarck, ND, USA
    Posts
    17
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That, and a few other minor syntax errors that I located, did indeed get my code compiling correctly. Now I'm just working on the myriad of logic issues that I've uncovered. Thank you.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •