2 / 67

Q02 - Same GET request parameter behavior

Considering the following HTML form code snippet and the servlet code, what will be the result of servlet invocation after the form has been submitted?

form.html:

<form action="myServlet?var=q1&var=q2" method="POST">
    <input name="var" type="hidden" value="q3" />
    <input type="submit" />
</form>

com.nullhaus.NullServlet:

package com.nullhaus;

import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.*;

@WebServlet("/myServlet")
public class NullServlet extends HttpServlet {
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        String param = req.getParameter("var");
        resp.getWriter().println("[" + param + "]");
    }
}