Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error Jsp Adding Subtracting Numbers

 
mike krony
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1784
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for your help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic