0

the web app is a simple calculator that adds and subtracts. my problem is that the add and the subtract buttons don't work

i get an error message: "An error occurred at line: 19 in the jsp file: /adder.jsp
Invalid character constant"

 <%
    String name = (String) session.getAttribute("name");
    if (name==null) {
            name = request.getParameter("name");
            if (name!=null) session.setAttribute("name",name);
    }

    String sum = (String) session.getAttribute("sum");
    if (sum==null) {
            sum = "0";
            session.setAttribute("sum",sum);
    }
    int isum = Integer.parseInt(sum);

    String number = request.getParameter("number");
    if (number==null) number = "0";
    int inumber = Integer.parseInt(number);
     switch(opchar){
   case 'add': 
    isum += inumber;
    session.setAttribute("sum",""+isum);
    break;
   case 'subtract': 
    isum += inumber;
    session.setAttribute("sum",""+isum);
    break;}
    %>
    <html>
    <head>
 <title>Adding Machine</title>
    </head>
    <body>
            <form method='get' action='adder.jsp'>
    <%
    if (name==null) {
    %>
                    <p>
                            Name: <input type='text' name='name' id='name'>
                    </p>
                    <p>
                            <input type='submit' name='submit' id='submit' value='signin'>
                    </p>
    <%
    } else {
    %>
                    <p>Welcome, <%=name%>!</p>
                    <p>Current sum is: <%=isum%></p>
                    <p>
                            Number to add: <input type='text' name='number' id='number' value='add'>
                    </p>
                    <p>
                           <% if (opchar == 'add') %> <input type='submit' name='submit' id='submit' value='add'>
                    </p>
                    <p>
                           <% if (opchar == 'suntract') %> <input type='submit' name='submit' id='submit' value='subtract'>
                    </p>
    <%
    }
    %>
            </form>
    </body>
    </html>
1
Contributor
1
Reply
2
Views
5 Years
Discussion Span
Last Post by koricha
0

i forgot the double quote but i still get an errors : "18 in the jsp file: /adder.jsp opchar cannot be resolved " and "An error occurred at line: 52 in the jsp file: /adder.jsp opchar cannot be resolved" i know i need to initialize opchar but dont know how .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.