greekos_kentos Posted April 6, 2005 Share Posted April 6, 2005 I'm tring to create a servlet that will calculate numbers input by the user but i'm a little stuck.This is what i have done so far<HTML><HEAD><TITLE>Call servlet to Calculate numbers</TITLE></HEAD><BODY><H1>Calculator</H1><P><FORM ACTION="/servlet/Add" METHOD=GET><P>First number : <INPUT TYPE=TEXT NAME=number1> <P>Second number : <INPUT TYPE=TEXT NAME=number2> <P><SELECT name=Action><OPTION value="" selected>- Select -</OPTION><OPTION value="+">Add</OPTION><OPTION value="-">Subtract</OPTION><OPTION value="/">Divide</OPTION><OPTION value="*">Times</OPTION></SELECT><P><INPUT TYPE=SUBMIT VALUE="Add the numbers"></FORM></BODY></HTML>// AdditionServlet.javaimport java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class Add extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res, HttpServletRequest req2) throws ServletException, IOException { res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream(); out.println("<HTML><BODY>"); out.println("We are pleased to inform you that the result " + "of your calculation is now ready:"); String[] number1params = req.getParameterValues("number1"); int number1 = Integer.parseInt(number1params[0]); String[] number2params = req.getParameterValues("number2"); int number2 = Integer.parseInt(number2params[0]); String[] actionparams = req.getParameterValues("action"); int action = Integer.parseInt(actionparams[0]); if (action == '+') { int sum = number1 + number2; out.println("<P>You kindly sent us the numbers " + number1 + " and " + number2); out.println("<P>The sum of the numbers is " + sum); out.println("</BODY></HTML>");} else { out.println("<P> Wrong value"); out.println("</BODY></HTML>");} }I'm getting the error "HTTP method GET is not supported by this URL"Any ideas what i have done wrong?? Link to comment Share on other sites More sharing options...
Taggs Posted April 7, 2005 Share Posted April 7, 2005 I've not done any programming for a while but this should point you towards the problem.This error means that the servlet identified by the URL does not implement the 'doGet' method, as a result a HTTP GET request cannot be successful.I hope this helps. Link to comment Share on other sites More sharing options...
matrix0978 Posted April 7, 2005 Share Posted April 7, 2005 Yes, I have a php calculator script it you would like that instead if the java. I will post it only if youll like it Link to comment Share on other sites More sharing options...
greekos_kentos Posted April 8, 2005 Author Share Posted April 8, 2005 Thanks For the advice and the offer, but I've managed to get it all working now Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now