<c:forEach items="${usersFromServer}" var = "user">
<tr>
<td class=w3-round-small>${user.firstName}</td>
<td>${user.lastName}</td>
<td>Пока нету даты</td>
<td><form action = "" method="post">
<input type="hidden" name="id" value="${user.firstName}">
<input type="hidden" name="name" value="${user.lastName}">
</form>
<form method="post">
<button type="submit" name="delete" value="${user.id}">Удалить</button>
</form>
<form method="post">
<button type="submit" name="update" value="${user.id}">Изменить</button>
</form>
</td>
</tr>
</c:forEach>
public class UserDaoJdbcImpl implements UsersDao{
/* language=SQL */
private final String SQL_SELECT_ALL =
"SELECT * FROM data_user";
/* language=SQL */
private final String SQL_CELECT_BY_ID =
"SELECT * FROM data_user WHERE id = ?";
/* language=SQL */
private final String SQL_DELETE =
"DELETE FROM data_user WHERE id = ?";
/* language=SQL */
private final String UPDATE_USER =
"UPDATE data_user SET firs_name=?, last_name=?";
private Connection connection;
public UserDaoJdbcImpl (DataSource dataSource) {
try {
this.connection = dataSource.getConnection();
}
catch (SQLException e)
{
throw new IllegalStateException(e);
}
}
@Override
public List<User> findAllByFirstName(String firstName) {
return null;
}
@Override
public Optional<User> find(Integer id) {
try
{
PreparedStatement statement = connection.prepareStatement(SQL_CELECT_BY_ID);
statement.setInt(1,id);
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
String firstName = resultSet.getString("firs_name");
String lastName = resultSet.getString("last_name");
Optional.of(new User(id, firstName, lastName));
}
return Optional.empty();
}
catch (SQLException e)
{
throw new IllegalStateException(e);
}
}
@Override
public void save(User model) {
}
@Override
public void update(User model) {
try{
PreparedStatement statement = connection.prepareStatement(UPDATE_USER);
statement.setString(1, model.getFirstName());
statement.setString(2,model.getLastName());
statement.executeUpdate();
}
catch (SQLException e)
{
throw new IllegalStateException(e);
}
}
}
<form action = "" method="post">
<input type="hidden" name="id" value="${user.firstName}">
<input type="hidden" name="name" value="${user.lastName}">
</form>
<form method="post">
<button type="submit" name="delete" value="${user.id}">Удалить</button>
</form>
<form method="post">
<button type="submit" name="update" value="${user.id}">Изменить</button>
</form>
<form method="post">
<input type="hidden" name="id" value="${user.firstName}">
<input type="hidden" name="name" value="${user.lastName}">
<button formaction="action1" type="submit" name="delete" value="${user.id}">Удалить</button>
<button formaction="action2" type="submit" name="update" value="${user.id}">Изменить</button>
</form>
formaction="..."
так вы можете внутри одной формы задать несколько разных видов actions. Внутри атрибута укажите action (url), куда должна отсылаться форма.Подскажите как перенаправить с одного jsp на другой для заполнения новой формы а после перенаправить данное изменение на сервлет.