Answer the question
In order to leave comments, you need to log in
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.
Answer the question
In order to leave comments, you need to log in
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>
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]));
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question