Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Method in JSP

Status
Not open for further replies.

wwworg

Programmer
Feb 10, 2006
35
CA
Hey guys

I am very new to JSP. I wanted to declare a method in JSP code, but its giving me an error. Error is

org.apache.jasper.JasperException: Unable to compile class for JSP.
An error occurred at line: 76 in the jsp file: /jsp/test20.jsp
Generated servlet error:
Unhandled exception type ParseException

and the code is

<code>

<%!
public String changeDateFormat(String str){
SimpleDateFormat df = new SimpleDateFormat("dd-M-yyyy");
java.util.Date tDate = new java.util.Date();
tDate = df.parse(str);
df = new SimpleDateFormat("dd-MMM-yyyy");
String date1 = df.format(tDate).toUpperCase();
return date1;
}
%>
<%
String theDate;
theDate = changeDateFormat(goodDate);
%>

</code>

its giving me error in line 76 which is the line that contains "<%!". Any thoughts on how to fix this???
 
LMAO ! I've seen that code for parsing dates before, and you didn't even say thankyou in the other thread. Some might consider that rude ... but never mind eh ?

Anyway, your code either needs to swallow java.text.ParseException, or throw it out to the calling code - eg :

Code:
    public String changeDateFormat(String str){
        try {
           SimpleDateFormat df = new SimpleDateFormat("dd-M-yyyy");
           java.util.Date tDate = new java.util.Date();
           tDate = df.parse(str);
           df = new SimpleDateFormat("dd-MMM-yyyy");
           String date1 = df.format(tDate).toUpperCase();
           return date1;
         } catch (java.text.ParseException pe) {

             //handle error
         }
          return null;
   }

or

Code:
public String changeDateFormat(String str) throws java.text.ParseException {

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sorry man.

I should have thanked you. I find this a great way to learn new stuff. You guys are just awesome. :)

Thx



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top