• Post Reply Bookmark Topic Watch Topic
  • New Topic

error with JSP

 
Lyle Harrington
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I'm getting the following compile error with my JSP page:

Note: sun.tools.javac.Main has been deprecated.
\ServletExec\Servlets\pagecompile\_PropertiesJSP_xjsp.java:14: The method void jspInit() declared in class pagecompile._PropertiesJSP_xjsp cannot override the method of the same signature declared in class com.newatlanta.servletexec.JSP10HttpJspPage. Their throws clauses are incompatible.
public void jspInit() throws java.io.IOException {
^
1 error, 1 warning

My code is:

<%!
private java.util.Properties props;
public void jspInit() throws java.io.IOException {
// private Properties props;
ServletConfig config = getServletConfig();
ServletContext context = config.getServletContext();
props = (java.util.Properties)context.getAttribute("props");
if (props == null){
loadProps();
props = new java.util.Properties();

}
}
public void loadProps() throws java.io.IOException {
props = new java.util.Properties();
try {
props.load(this.getClass().getResourceAsStream("/project3.properties"));
} catch (IOException ioe) {
System.out.println("Can't load the properties file");
ioe.printStackTrace();
} catch (Exception e) {
System.out.println("Problem: " + e);
e.printStackTrace();
}
}
%>

<html> <html>
<head>
<title>Project Information Page</title>
</head>
<center><body>
<h3>The Project Information Page is a JSP page that displays elements in a properties file</h3>

<table border cellspacing=0 cellpadding=4>
<tr><td><b>Author</b></td>
<td><%= out.println(props.getProperty("author")) %></td></tr>
<tr><td><b>Email</b></td>
<td><%= out.println(props.getProperty("Email")) %></td></tr>
<tr><td><b>Course</b></td>
<td><%= out.println(props.getProperty("Course")) %></td></tr>
<tr><td><b>Schedule</b></td>
<td><%= out.println(props.getProperty("Schedule")) %></td></tr>
<tr><td><b>Instructor</b></td>
<td><%= out.println(props.getProperty("Instructor")) %></td></tr>
<tr><td><b>Description</b></td>
<td><%= out.println(props.getProperty("Description")) %></td></tr>
</table></center></body>
</html>
}

Thanks
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Several points to note here.

1. You handle all exceptions in your loadProps() method by a sysout statement. This is dangerous practise and hell to debug.

2. Since you catch all exceptions in your loadProps() method, why do you declare the method throw IOException ?

3. You cannot override a method with an incompatible throws clause - jspInit() throws a ServletException, so catch your IOException and throw a ServletException from within init().

I have made changes to your code and it deals with all points noted above.




ram.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i just noted, in my post above, all the throw statements should be the last call in the catch block i.e after the sysout statements, sorry for the error.

ram.
 
Lyle Harrington
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I tried it and am still getting the same error message. You asked why all Exceptions in the loadProps() are handled with a sysout statement. That method was actually given to us by our instructor to use in this assignment, that's just what he told us to use. We're just learning about Exceptions and how to handle them. Why is doing it that way dangerous and difficult?

I tried your changes and am still getting the same error. I also had tried changing my throws statement in jspInit() and loadProps() to Servlet Exception earlier with the same result. The reason I put java.io.IOException is that in the specs for our assignment it says we have to use the full name for the java.io.IOException and states this in refernce to the jspInit(). That statement has me confused.

One thing I don't understand about the error I'm getting is the statement:
sun.tools.javac.Main has been deprecated. I can't see there's anything I'm using in my code that would be deprecated including what I've tried in my throws clauses. I'm not sure what I'm doing wrong but thanks for your help!
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Thanks for the reply. I tried it and am still getting the same error message. You asked why all Exceptions in the loadProps() are handled with a sysout statement. That method was actually given to us by our instructor to use in this assignment, that's just what he told us to use. We're just learning about Exceptions and how to handle them. Why is doing it that way dangerous and difficult?


You will understand the whys of it after mastering exception handling. But here are a few hints - u expect your code in loadProps() method to load you Properties object viz, props. Now while doing this, if an exception occured, control would pass to your catch block (bcos you have chosen to handle it). All you do there is print out the exception - you dont have any fallback strategy there. The program continues and if you ever access the props Object subsequently, you would end up with a null pointer exception because the props object was never loaded (it threw an exception while loading, remember)


I tried your changes and am still getting the same error.


Funny, can you check what's this class com.newatlanta.servletexec.JSP10HttpJspPage ? I assumed that, that would be the superclass of all jsp generated servlets.

The exception states that the throws clause is imcpoatible. This happens when a method is overridden in the sub-class with a throws clause that's different from the one declared in the base class method. (The throws clause can be ignored provided the exception is handled in the sub-class overridden method or narrowed to a more specific one )


One thing I don't understand about the error I'm getting is the statement:
sun.tools.javac.Main has been deprecated. I can't see there's anything I'm using in my code that would be deprecated including what I've tried in my throws clauses. I'm not sure what I'm doing wrong but thanks for your help!


That's a red herring. It means that the entry point of the javac compiler (i.e it's main has been deprecated someday - Sun wouldn't support it - there would be some other elegant way that it would be done) - its nothing to do with your code

ram.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

[ March 09, 2005: Message edited by: Ben Souther ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!