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

  • Home
  • SEARCH
  • 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 8515663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:12:38+00:00 2026-06-11T05:12:38+00:00

I am having a problem with a .jsp page I am creating. For those

  • 0

I am having a problem with a .jsp page I am creating. For those worried, the site was for homework, however, I am trying to go beyond what is required and am not asking anything related to grading. This is strictly for my own benefit.

Down to business:
I am getting an input from the user, performing a method=”post” and refreshing the page, and in an ideal situation it works (that was the homework.) However, I am trying to make a try/catch block in the case where a user enters a string into an int field.

int Svolt = 0;
double Amperes = 0.0;
double LEDdrop = 0.0;

if (request.getParameter("Svolt") != null) {
try {
    Svolt = Integer.parseInt(request.getParameter("Svolt")); 
} catch ( NumberFormatException e ) {
    %>
    <script type ="text/javascript">
        alert("The source voltage must be an integer. Please fix this.");
    </script>
    <%                                                    
}

I’ve tried switching “NumberFormatException” to “Exception”, but it returned the same error code.
Earlier, I had my try catch come before the if() statement, and it worked, but didn’t display the alert box I want.

That code is below:

final double MA_TO_A = 0.001;
int Svolt = 0;
double Amperes = 0.0;
double LEDdrop = 0.0;

try {
    if (request.getParameter("Svolt") != null) {
        try {
            Svolt = Integer.parseInt(request.getParameter("Svolt"));
        } catch (Exception e) 
        {
            %>
            <script type ="text/javascript">
                alert("The source voltage must be an integer. Please fix this.");
            </script>
            <%
        }
        Amperes = Double.parseDouble(request.getParameter("Amperes"));
        LEDdrop = Double.parseDouble(request.getParameter("LEDdrop"));

        out.println("Ideal resistance is: " + ((Svolt - LEDdrop) / (Amperes * MA_TO_A)) + " Ohms.");   
    }
} catch (Exception e) {
        out.println("Please make sure your inputs are correct.");
}

Any help is appreciated, and your time is, too. Thank you very much!

EDIT:
Sorry, meant to copy-paste the error code:

org.apache.jasper.JasperException: java.lang.NumberFormatException: For input string: "a"

Where the tested input was the string “a”

EDIT2:
Back-up/edit/test @Nambari’s suggestion

final double MA_TO_A = 0.001;
int Svolt = 0;
double Amperes = 20.0;
double LEDdrop = 1.8;

try {
    if (request.getParameter("Svolt") != null) {
        try {
            Svolt = Integer.parseInt(request.getParameter("Svolt"));
        } catch (Exception e) 
        {
            %>
            <script type ="text/javascript">
                alert("The source voltage must be an integer. Please fix this.");
            </script>
        <%
        }
        out.println("Ideal resistance is: " + ((Svolt - LEDdrop) / (Amperes * MA_TO_A)) + " Ohms.");   
    }
} catch (Exception e) {
    out.println("Please make sure your inputs are correct.");
}

Output:
Ideal resistance is: -90.0 Ohms

Alert box saying (“The source voltage must be an integer. Please fix this.”)

No error code.

No out.println saying (“Please make sure your inputs correct”).

FINAL EDIT:

Code now works almost as desired, but good enough.

                    final double MA_TO_A = 0.001;
                    int Svolt;
                    double Amperes;
                    double LEDdrop;

                    if (request.getParameter("Svolt") != null) 
                    {
                        try 
                        {

                            try 
                            {
                                Svolt = Integer.parseInt(request.getParameter("Svolt"));
                            } catch (Exception e) 
                            {
                            %>
                            <script type ="text/javascript">
                                alert("The source voltage must be an integer. Please fix this.");
                            </script>
                            <%  
                            Svolt = 0;
                            }
                            try 
                            {
                                Amperes = Double.parseDouble(request.getParameter("Amperes"));
                            } catch (Exception e) 
                            {
                                %>
                                <script  type = "text/javascript"> 
                                    alert("The source voltage must be an integer. Please fix this.");
                                </script> 
                                <% 
                                Amperes = 0.0;
                            }
                            try 
                            {
                                LEDdrop = Double.parseDouble(request.getParameter("LEDdrop"));
                            } catch (Exception e) 
                            {
                            %>
                                <script  type = "text/javascript"> 
                                    alert("The source voltage must be an integer. Please fix this.");
                                </script> 
                            <%
                            LEDdrop = 0.0;
                            }
                            out.println("Ideal resistance is: " + ((Svolt - LEDdrop) / (Amperes * MA_TO_A)) + " Ohms.");
                        } catch (Exception e)
                        { 
                            out.println("Please make sure your inputs are correct."); 
                        }   
                    }

Lots of jargon, I know, but that’s the end result. Somehow, this has it all working. Thank you to all who helped!

  • 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-11T05:12:39+00:00Added an answer on June 11, 2026 at 5:12 am

    This is posted as answer based on my comments:

    I would suggest remove everything except the Svolt related code on your form and try. I think something else messing up than this filed. Take a backup of existing code. Remove everything except Svolt and see, we can nail down the issue.

    Make sure try/catch blocks are properly synched with code flow as suggested in above comments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem trying to serve a zip file in a JSP. The
Having problem with the middle Div not expanding to the width http://acs.graphicsmayhem.com/images/middiv.jpg Ok, how
iam having a jsp page Index.jsp which accept a only unicode string as its
I am having an update statament in my jsp. The problem is that when
I'm creating a site on which there are many page components that refer to
I have a drop down in a jsp page having the following code <s:select
I'm trying to create a servlet which loads FirstJSP.jsp in WEB-INF/jsp/FirstJSP.jsp I'm having a
I am having a problem with javax.xml.transform.Transformer . I am trying to create a
I am having some frustrating javascript timing issues. FYI, the page is a jsp
Hi im pretty new to jsp and servlets so im having a problem understanding

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.