Get all parameters from JSP page

后端 未结 6 1372
无人共我
无人共我 2020-12-01 03:33

I have n number of text fields named in the form \"Question.....\". How can I get all the parameters which starts with \"question\" from the JSP page to the Action?

6条回答
  •  广开言路
    2020-12-01 04:03

    The fastest way should be:

    <%@ page import="java.util.Map" %>
    Map parameters = request.getParameterMap();
    for (Map.Entry entry : parameters.entrySet()) {
        if (entry.getKey().startsWith("question")) {
            String[] values = entry.getValue();
            // etc.
    

    Note that you can't do:

    for (Map.Entry entry : 
         request.getParameterMap().entrySet()) { // WRONG!
    

    for reasons explained here.

提交回复
热议问题