• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Method visibility among classes...

 
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sure that I'm just missing something very small here. This is more of a method visibility issue than a servlet issue so that is why I'm posting here. I have a servlet class, and I have another class for with DB connecting and RS returning. I'll post the snippets and then describe the error...

My servlet code...



This is just a snippet, I have some 'if' logic below the request.setAttribute, but that doesn't do anything except build a string and blah blah.

Here is the code for the connection class...



That is the whole class with both methods. My error is in the servlet class. In the line that says 'Connection opnConn = opnAS400Conn(url, libraryName, userName, password);' I am getting an error that says...

'The method opnAS400Conn(String, String, String, String) is undefined for the type FormManager'

FormManager is the name of my servlet, opnAS400Conn is the method in my class ConnDB. They are both part of the same package and both classes know that.

Why can't my servlet see that method in the other class?
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to call

 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. So my code now looks like this...



But it tells me

Default constructor cannot handle exception type Exception thrown by implicit super constructor.
Must define an explicit constructor



I'm going to dig around to figure out why this is, if anyone knows I would surely appreciate the help.
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem seems to be in this line of your Servlet class:



Note 2 things about this statement:
- It can throw an Exception
- It is executed by the constructor

I'm not a servlet expert so I don't know whether or not its legal to declare a constructor that can throw an exception. You could probably create the connection in the init() method and try to catch the exception, rethrowing it as a ServletException if needed.
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply Tim. That took care of that error. My next question is this...

Down in my doPost I have some 'if' statements. They build a string buffer and then call this...



I use the opnConn that I created in the init() method. But it says opnConn cannot be resolved. Do I need to return it out of my init() method in order for my other methods to see it?
 
Bryce Martin
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't have the right scope. I had to declare

above my init() method. Then the other methods could see it once I initialized it. Everything seems to be going ok for now. I'll know in a couple hours if this is going to work.
 
I have gone to look for myself. If I should return before I get back, keep me here with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic