Hi,
I have the following code:
<HTML>
<HEAD>
<TITLE>Project 4-1</TITLE>
</HEAD>
<BODY>
<% String amount = request.getParameter("sales");
if(amount == null) amount = "0";
int sales = Integer.parseInt(amount);
double comis = 0; //commission stored here
double total = 0;
%>
<b>Enter the amount of your sales:</b>
<form name="thisForm" action="Project1.jsp" method=post>
Amount of sales:<input name=sales size=10>
<input type=submit value="Get commissions">
</form>
<% if (sales>=1 && sales<=2000) {
comis = (sales*0.03);
total = (comis+sales);
} else if (sales>=2001 && sales<=5000) {
comis = (sales*0.04);
total = (comis+sales);
} else if (sales>=5001 && sales<=7000) {
comis = (sales*0.07);
total = (comis+sales);
} else if (sales>=7001) {
comis = (sales*0.10);
total = (comis+sales);
}%>
<% out.print("Sales is "+sales+" Commission is "+comis+" Total is " + total);
%>
</BODY>
</HTML>
It works ok but if I don't enter a value or enter a non numeric value in the sales field I receive an error.
How can I check if nothing or a non-numeric value is entered. I would rather not do it as a try-catch though.
I have the following code:
<HTML>
<HEAD>
<TITLE>Project 4-1</TITLE>
</HEAD>
<BODY>
<% String amount = request.getParameter("sales");
if(amount == null) amount = "0";
int sales = Integer.parseInt(amount);
double comis = 0; //commission stored here
double total = 0;
%>
<b>Enter the amount of your sales:</b>
<form name="thisForm" action="Project1.jsp" method=post>
Amount of sales:<input name=sales size=10>
<input type=submit value="Get commissions">
</form>
<% if (sales>=1 && sales<=2000) {
comis = (sales*0.03);
total = (comis+sales);
} else if (sales>=2001 && sales<=5000) {
comis = (sales*0.04);
total = (comis+sales);
} else if (sales>=5001 && sales<=7000) {
comis = (sales*0.07);
total = (comis+sales);
} else if (sales>=7001) {
comis = (sales*0.10);
total = (comis+sales);
}%>
<% out.print("Sales is "+sales+" Commission is "+comis+" Total is " + total);
%>
</BODY>
</HTML>
It works ok but if I don't enter a value or enter a non numeric value in the sales field I receive an error.
How can I check if nothing or a non-numeric value is entered. I would rather not do it as a try-catch though.