Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7789519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:19:21+00:00 2026-06-01T21:19:21+00:00

I am writing a simple web app that performs calculations. I have 2 buttons,

  • 0

I am writing a simple web app that performs calculations. I have 2 buttons, for adding and subtracting, but they aren’t working. I tried to use a switch statement and an if statement, but neither are working. Could you please assist me to understand the problem.

Here is my code…

<%
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);
if(request.getParameter("add") != null){ 
    isum += inumber;
    session.setAttribute("sum",""+isum);
}
if(request.getParameter("subtract") != null){
    isum += inumber;
    session.setAttribute("sum",""+isum);
}
%>

<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>
                     <input type='submit' name='submit' id='submit' value='add'>
                </p>
                <p>
                    <input type='submit' name='submit' id='submit' value='subtract'>
                </p>
            <%
            }
            %>
        </form>
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:19:23+00:00Added an answer on June 1, 2026 at 9:19 pm

    It seems you have badly copied example from somewhere:

    Syntax of request.getParameter() is :

    request.getParameter("formParamName");
    

    Read More at : Java Docs

    Here you will definately get NULL as there is no parameter named “add” or “subtract”.

    Change your code to

    if(request.getParameter("submit") != null){ 
    
        if(request.getParameter("submit").equals("add"))
            isum += inumber;
        else if(request.getParameter("submit").equals("subtract"))
            isum -= inumber;
        session.setAttribute("sum",""+isum);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple web app in PHP that needs to have write access
I am writing an app that’s a very simple web service client. I have
Imagine you're writing a web app that will have 1 million users (they all
I'm writing a simple Facebook status update web app that uses Graph API. It
I am writing a simple rails app that caches values from a web service.
I'm writing a web app that at one point allows a user to upload
I am writing a simple ASP.NET MVC web app. At this point, I am
At work we have a web app that we'll need to interface with another
I am writing a simple web app using Linq to Sql as my datalayer
I am writing a simple salesforce app that requires app-level and user-level configuration. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.