i am trying to add two no. from the 1st two text boxes and display the sum in the 3rd text box after clicking the submit button and all work should be done on one single jsp page.. please help
the exception i am getting is mentioned below...
HTTP Status 500 -
type Exception report
description The server encountered an internal error () that prevented it from fulfilling this request.
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 23
20: <input type="text" name="t3"/><br>
21: <input type="submit" value="ADD"/>
23: <% Integer a = Integer.valueOf(request.getParameter("t1"));
24: Integer b = Integer.valueOf(request.getParameter("t2"));
25: Integer c = Integer.valueOf(request.getParameter("t3"));
26: Integer o = a+b ;
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.
My jsp code is mentioned below...
Document : index
Created on : 14 Jul, 2011, 10:41:42 AM
Author : aNsH
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
i want to create 3 text fields and one submit button on one page where i can enter any 2 values in the first two text boxes and the sum should be displayed in the third text box on the same page..
and i want the coding in a single page of JSP..
please help.. i have been trying for so long..
Did you understand my post? Did you read the article? If you have not, do it now.
As I said, the first time that the page is displayed (before it is submitted through the form to itself) there can be no parameters. Your code does nothing to account for that situation. Hence, the null pointer exception when you try to use parameters that do not exist.
I trust that this is either homework or a learning exercise?
Joined: Apr 13, 2013
yeah ive gone through that article but could not get any help... and yes it was a question asked by my trainer..
n yeah i know the first time the page will be displayed there would not be any parameters.. so that is what i want to know
that what should i do to display the sum in the third text box in the same page..???
what i was thinking is that i can check if the third text box is empty/null it would calculate the sum n display i the third text box.. but how to do all that in the same page??
at least give me the logic if not code ??
You only have one page, so anything that's going to happen is all going to happen in the "same page" no matter what. If that's the case, you need to check if there are any values, which will only be present the second time that the page displays after the user enters them in the boxes and submits the form.
Or, do you mean that you need to display the answer without the user submitting the form?
I guess you need to explain what you mean by "same page"
Joined: Apr 13, 2013
i want the initially there must be 3 empty text boxes and one submit button..
i want the user to enter values in the first two text boxes leaving the third text box empty then after clicking the submit button the first two text boxes remain the same with the previously filed value but their sum should be displayed in the third text box on the same page...
=>Use a servlet for handling the calculation and store the result in the request.
=>Forward the Servlet back to the same JSP
=>On your JSP,in the value attribute for your text box ,write a scriptlet to get the request value.(Also add additional condition to display empty string if the value is not available in the request to avoi d Null Pointer exceptions)
Refer any basic JSP tutorial for knowing how to do scriptleting.