This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Error Jsp Adding Subtracting Numbers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Error Jsp Adding Subtracting Numbers" Watch "Error Jsp Adding Subtracting Numbers" New topic
Author

Error Jsp Adding Subtracting Numbers

mike krony
Greenhorn

Joined: Apr 15, 2012
Posts: 5
this 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 the following 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

Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1016
#1 don't put java code in a jsp. Java code belongs in a java class.
#2 Unless you're using java 7, you can't switch on a String.
#3 You can't compare strings with ==. Use the equals() method.
#4 The subtraction operator is '-', not '+'

To initialize opchar you need to declare the variable, and give it a value.

something like:

Depending upon which button you clicked in your form, the value of opchar would then be either 'add' or 'subtract'
mike krony
Greenhorn

Joined: Apr 15, 2012
Posts: 5
thanks for your help
 
Don't get me started about those stupid light bulbs.
 
subject: Error Jsp Adding Subtracting Numbers
 
Similar Threads
Tag throwing null
problem in inserting session data in jsp/servlet application
passing hidden forms problem
Session Value Persistence
My Shopping cart does not work