Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Enumerator type error on getInitParameterNames  RSS feed

 
sage erosenin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get all the Init Parameter Names by calling the getInitParameterNames() on the ServletConfig config object passed to the httpServlet's init Constructor.



Error as below
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you getting a request dispatcher in init? You never even do anything with it.

Rule #1: eliminate all superfluous code.

Clean up your code and see if the problem persists.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
at com.website.Home.doGet(Home.java:52)


If you look carefully at these two lines of stack trace, they say that the error occurred inside a "forward" method which was called from the "doGet" method of your Home class. But in the version of the Home class you posted, the doGet method doesn't call any forward method anywhere. So the code you posted is not the code which threw that exception.

Edit: Sorry, I didn't look carefully enough. You didn't even post the doGet method, you only posted the init method. You must have assumed that it was the init method causing the problem, but the stack trace clearly shows otherwise.
 
sage erosenin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting, even before i try to debug. I wish to understand how you inferred the problem was with forward, at the head of the stack trace is

java.lang.ClassCastException: org.apache.catalina.util.Enumerator cannot be cast to java.lang.String


wouldn't you normally think its the issue with Enumeration ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The rest of the stack trace shows how it got there. And that does not jive with your code.
 
sage erosenin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Makes sense, and the point of first inference would be

at com.website.Home.doGet(Home.java:52)


is my understanding correct ?
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sage erosenin wrote:... at the head of the stack trace is

java.lang.ClassCastException: org.apache.catalina.util.Enumerator cannot be cast to java.lang.String


wouldn't you normally think its the issue with Enumeration ?


Well, no, because Enumerator and Enumeration aren't the same thing. But for your later question, yes, your understanding of how to read the stack trace to find the point in your code which ultimately led to the exception is correct.
 
sage erosenin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not trying to do anything fancy here. Just want to look at all names of the Init parameters. I get the error which i posted earlier.

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you're still trying to cast that Enumerator to a String in your JSP. (Yes, in the JSP. It's pretty clear from the top part of the stack trace that the error is thrown in a JSP.) So you should have a look at the JSP, in particular the part where you try to use that request attribute.
 
sage erosenin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Well, you're still trying to cast that Enumerator to a String in your JSP. (Yes, in the JSP. It's pretty clear from the top part of the stack trace that the error is thrown in a JSP.) So you should have a look at the JSP, in particular the part where you try to use that request attribute.


Ok. All i wish to do is list all the InitParameterNames in my JSP. What is the best way of going about it ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fetch the Enumeration in the servlet. Iterate over the names collecting them into a List. Establish the list as a scoped variable in request scope. Iterate over the list in the JSP using <c:forEach>.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!