Aunt Phyllis
Aunt Phyllis

Reputation: 1

How to send parameters from a JSP page to a Servlet without a <form> element

I'm trying to send a string containing a "command" to my Servlet controller's doGet method and request.getParameter().

The tutorial I watched on this subject used both a form tag and a param tag embedded in a link to send params back to the doGet.

Link and param:

<c:url var="deleteLink" value="StudentControllerServlet">
                <c:param name="command" value="DELETE" />
                <c:param name="studentId" value="${tempStudent.id}" />
            </c:url>

Form:

<form action="StudentControllerServlet" method="GET">

        <input type="hidden" name="command" value="UPDATE">

        <input type="hidden" name="studentId" value="${THE_STUDENT.id}">

        <table>
            <tbody>
                <tr>
                    <td><label>First Name:</label></td>
                    <td><input type="text" name="firstName" value="${THE_STUDENT.firstName}"/></td>
                </tr>
                <tr>
                    <td><label>Last Name:</label></td>
                    <td><input type="text" name="lastName" value="${THE_STUDENT.lastName}" /></td>
                </tr>
                <tr>
                    <td><label>Email:</label></td>
                    <td><input type="text" name="email" value="${THE_STUDENT.email}" /></td>
                </tr>
                <tr>
                    <td><label></label></td>
                    <td><input type="submit" value="Save" class="save" /></td>
                </tr>
            </tbody>
        </table>
    </form>

Neither of these work for me, I want to click a button that takes me to another page and simultaneously sends a param back to the doGet.

Is there a good way to do this, or am I doing it wrong?

Upvotes: 0

Views: 100

Answers (1)

mentallurg
mentallurg

Reputation: 5207

Yes, you can do that. In the servlet that you trigger via GET request, first process the parameter that your browser sent to the servlet. Then you can send browser to another URL using sendRedirect(). See an example here.

Upvotes: 1

Related Questions