RSS Forums RSS
Please support our JSP advertiser: Lunarpages JSP Web Hosting

variable Initialisation in JSP

Join Date: Dec 2006
Posts: 54
Reputation: staneja is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 1
staneja's Avatar
staneja staneja is offline Offline
Junior Poster in Training

Question variable Initialisation in JSP

  #1  
Mar 16th, 2007
I am new to JSP and was trying a very simple program that adds/Divide/multiply/Subtract 2 numbers
I am taking two numbers from a web page and as per the button pressed performing the action on JSP page. I have kept a vraiable c for output

If i write int c=0 ;then it works fine but if i only write int c and then code its not working
I have never observed this behavior in core Java.Is variable initialisation is mandatory in JSP.FOllowing is code i am using that throws exception

 <body><% 
            int a=Integer.parseInt(request.getParameter("t1"));
            int b=Integer.parseInt(request.getParameter("t2"));
            int c ;
            String label=request.getParameter("b1");
            if (label.equals("add"))
                c=a+b;
            else
                if (label.equals("sub"))
                c=a-b;
                else
                    if (label.equals("mul"))
                    c=a*b;
                    else
                        if (label.equals("div"))
                        c=a/b;
        %>
         <% out.print(c);%>
    </body>
AddThis Social Bookmark Button
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:57 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC