JSP

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>

 

 

 

 

jsp

 

about author

PHRASE

Level 60  머나먼나라

고기가 썩으면 구더기가 생기고, 생선이 마르면 좀벌레가 생긴다. 나태함으로써 자신을 잊는다면 재앙이 곧 닥칠 것이다. -순자

댓글 ( 4)

댓글 남기기

작성