Hello all,
I'm working through some examples of java servlets. I have one example of a servlet taking text input, the lines of code I have an example of are below, this example uses a html text area to submit input:
String text = req.getParameter("text"); String translation = translate(text); res.setContentType("text/html"); ServletOutputStream out = res.getOutputStream();
I am doing my own example working with html radio buttons and was thinking of altering the code to how it is below, my questions concern mainly the first 4 lines:
String colour = req.getParameter("colour"); res.setContentType("radio/html"); ServletOutputStream out = res.getOutputStream(); out.println("<html>"); out.println("<body>"); out.println("<head><title>Change Colour</title></head>"); out.println("<h1><p>Background Colour</p></h1>"); out.println("<p>What colour do you want the background?</p>"); out.println("<form>"); out.println("Yellow <input type=\"radio\" name=\"colour\" value=\"Yellow\" /> </br>"); out.println("Green <input type=\"radio\" name=\"colour\" value=\"Green\" /> </br>"); out.println("Blue <input type=\"radio\" name=\"colour\" value=\"Blue\" /> </br>"); out.println("<input type=submit value=\"Change Background\"/>"); out.println("</form>"); out.println("</body>"); out.println("</html>");
All I would like to know is am I passing the correct parameter into the HttpServletResponse method getParameter()? Colour is the name of the radio button group. Am I write in making the object a string? Finally once I get the parameter will I be able to check against it if (colour == "Yellow") for example. Any help much appreciated.