CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2012
    Posts
    6

    jsp Exception error

    i am having a problem with the continue button when i don't enter anything in the text field i get an error "org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 18" i know something is wrong with my exceptions but i am not sure what .
    please help .


    <%@ page import="java.io.*"%><%@
    page import="java.util.*"%><?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    </head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <%
    String sum = (String) session.getAttribute("sum");

    sum = "5";
    session.setAttribute("sum",sum);

    int isum = Integer.parseInt(sum);
    try {
    isum=Integer.parseInt(request.getParameter("number"));
    } catch (NumberFormatException nfe){ out.println("Error!");}
    if(request.getParameter("number")!=null && Integer.parseInt(request.getParameter("number"))==isum)
    {
    if(request.getParameter("submit") != null){
    out.print("Hello");}
    }
    %>

    <body>
    <title>MAIN</title>
    <form action="index.jsp" method="post">
    Enter 5 = <input type="text" name="number">
    <input type="submit" value="continue" name="submit">
    </form>


    </body>
    </html>

  2. #2
    Join Date
    May 2006
    Location
    UK
    Posts
    4,473

    Re: jsp Exception error

    The problem is the if statement on line 18.

    I imagine request.getParameter("number") is returning an empty string and so Integer.parseInt() is throwing a number format exception. I don't understand why you are using this if statement here why not handle the logic in the try catch block above.
    Posting code? Use code tags like this: [code]...Your code here...[/code]
    Click here for examples of Java Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured