759
No
UpdateUserServlet
package com.slipp.user;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/users/update")
public class UpdateUserServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userId=request.getParameter("userId");
String password=request.getParameter("password");
String name=request.getParameter("name");
String email=request.getParameter("email");
User user=new User(userId, password, name, email);
UserDAO userDAO=new UserDAO();
userDAO.updateUser(user);
response.sendRedirect("/");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
test
public User add(){
User user =new User();
user.setName("홍길동");
user.setPassword("1111");
user.setUserid("qqq");
user.setEmail("aaa@aaa");
dao.removeUser(user.getUserid());
dao.insert(user);
return user;
}
@Test
public void updateUser() {
User user= add();
user.setName("김길동");
dao.updateUser(user);
}
<form class="form-horizontal" action="/users/update" method="post">
<div class="control-group">
<label class="control-label" for="userId">사용자 아이디</label>
<div class="controls">
<input type="hidden" name="userId" value="${user.userid }" />
${user.userid }
</div>
</div>
<div class="control-group">
<label class="control-label" for="password">비밀번호</label>
<div class="controls">
<input type="password" id="password" name="password" placeholder="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="name">이름</label>
<div class="controls">
<input type="text" id="name" name="name" value="${user.name }" placeholder="">
</div>
</div>
<div class="control-group">
<label class="control-label" for="email">이메일</label>
<div class="controls">
<input type="text" id="email" name="email" value="${user.email}" placeholder="">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">정보수정</button>
</div>
</div>
</form>
댓글 ( 4)
댓글 남기기