-1

Basically I have two radiobuttons here, with different values, now when submitted the next page should display the selection. But it does not, when i try this with type=text it works fine. Please help.

<form action="Confirm.jsp">
  <p>
    This is a simple HTML page that has a form in it.
    <br>form data is: <strong>${param.QuizAnswer}</strong>
    <p>
      Hobby:
      <input type="radio" name="QuizAnswer" value="cats">Cats


      <input type="radio" name="QuizAnswer" value="dogs">Dogs


      <input type="submit" name="submit" value="submit">
</form>

And other page has this in the body:

<body>
  <p>
    This is barebones, sorry.

    <p>The Data was entered as:
      <strong>${param.QuizAnswer}</strong>
</body>
Phil
  • 157,677
  • 23
  • 242
  • 245

2 Answers2

0

Plz change the receiving page as following way

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
      <c:choose>
     <c:when test="${empty param.QuizAnswer}">
        Please enter your name.
    </c:when>
    <c:otherwise>
        Hello <b><c:out value="${param.QuizAnswer}" /></b>!
    </c:otherwise>
</c:choose>
    </body>
</html>

Please check it and let me know

ASADUL
  • 308
  • 5
  • 17
-1

By sending the form to Confirm.jsp, you're sending the form data to the back-end as an actual form submit. If that's what you want, you should handle the form parameters on the back-end.

If you're wanting to use a form submit to change things on the front-end, you should send the form to an empty destination (form action="") and handle the submit in a javascript event handler. Here's an example:

Print value on form submit

Community
  • 1
  • 1
coderkevin
  • 359
  • 1
  • 5
  • What? That just confused me, I'm sorry its that I am a bit new to this. – Pursuer of Dying Stars Feb 19 '15 at 05:21
  • It appears you want to do one of two things here: Option 1, Send a radiobutton selection to the webserver and use that information on the server, then display the result on the next page. If that's the case, you probably want to handle it in the response instead of display the previous request params. Option 2, you just want to change the current page based on the radiobutton selection. If that's the case, you should handle it in javascript on the page, so you don't have to make a round-trip to the server. That's the link I posted on the answer. – coderkevin Feb 19 '15 at 05:27
  • Not really, the selection is already on the query string as: QuizAnswer=cats&submit=submit All I want is to use the parameter, in this case QuizAnswer and display it on the webpage. Like one would display a variable. I know it should be easy, since if it were type=text instead of type=radio it would work flawlessly – Pursuer of Dying Stars Feb 19 '15 at 05:39