JSP JAVA: Illegal start of type try-catch -


i've looked @ several posts pertaining same problem i'm having can't figure out how fix mine. add public class i'm met more errors. error @ line 1 comment fine before add try-catch. (code skips try catch is)

<%            string curr1 = request.getparameter("lstcurrency1");     string curr2 = request.getparameter("lstcurrency2");     string errormessage = null;      try {     double currin = double.parsedouble(request.getparameter("txtcurrency1"));                 double convert = fxdatamodel.getfxrate(curr1,curr2)*currin;     }     catch (numberformatexception ex){          errormessage = "please insert valid number!";     }     string[] currencies = fxdatamodel.getfxcurrencies();  %> 

this code above html page draws on currin , convert fill textboxes. here works fine until add try-catch. have read might need add public class everytime try gives me more errors , "request" no longer recognized. me figure out why it's saying illegal start of type?

thanks

you declare variables in try block therefore can used in block.

therefore put declaration outside of try-block:

double currin = null, convert = null; try {     currin = double.parsedouble(request.getparameter("txtcurrency1"));                 convert = fxdatamodel.getfxrate(curr1,curr2)*currin; } catch (numberformatexception ex){      errormessage = "please insert valid number!"; } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -