M
M
MrBe2016-02-11 23:20:44
Java
MrBe, 2016-02-11 23:20:44

Is it possible to send a List with jsp?

There is an object of type Resource. Its fields are: id, title, List, Date, Status. The Author object has its own fields, which we also output to jsp. How to display everything on jsp is clear, the question is how, when sending a POST request to a servlet, collect the List back and send it as a sheet. Is it possible? Preferably without Spring.
0a12c79efd2b46c59ce19f18dd8142a1.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
smartchecker, 2016-02-12
@MrBe

JSON

E
Evhen, 2016-02-12
@EugeneP2

For example, there is a form

<form ...>
  <input name="lastName" value="Ivanov" />
  <input name="firstName" value="Ivan" />

  <input name="lastName" value="Petrov" />
  <input name="firstName" value="Petr" />
</form>

In a servlet, a request from such a form without frameworks can be processed like this
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  // тут будит lastNames = {"Ivanov", "Petrov"}
  String[] lastNames = request.getParameterValues("lastName");

  // тут будит firstNames = {"Ivan", "Petr"}
  String[] firstNames = request.getParameterValues("firstName");

  List<Author> author = new ArrayList<Author>();

  for (int i = 0; i < lastNames.length && i < firstNames.length; i ++)  {
  
    author.add(new Author(firstNames[i], lastNames[i]));
  }
}

something like this...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question