- 회원 정보를 입력(memberForm.html)
- 회원정보를 작성하기(memberForm.html)
- 회원정보 상세페이지 (memberView.jsp)
총 필요한 코드 : memberForm.html(입력), memberView.jsp(결과 화면단), memberServlet.java(객체생성하고 데이터 삽입), MemberVO.java(데이터 객체)
1)memberForm.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="/edu/inform1">
<h1>회원 정보를 입력하십시오.</h1><hr>
<input type="text" name="name" placeholder="이름을 입력하세요"><br>
<input type="text" name="phone" placeholder="전화번호를 입력하세요"><br>
<input type="text" name="account" placeholder="계정을 입력하세요"><br>
<input type="text" name="passwd" placeholder="패스워드를 입력하세요"><br>
<input type="submit" value="등록">
<input type="reset" value="재작성">
</form>
</body>
</html>
2)memberView.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="vo.MemberVO"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
회원정보<hr>
<ul>
<% MemberVO m = (MemberVO)request.getAttribute("member"); %>
<li>회원 이름 : <%= m.getName() %> </li>
<li>회원 전화번호 : <%= m.getPhone() %></li>
<li>회원 계정 : <%= m.getAccount() %></li>
<li>회원 암호 : <%= m.getPasswd() %></li>
</ul>
</body>
</html>
3)memberServlet.java
package controller;
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;
import vo.MemberVO;
@WebServlet("/inform1")
public class MemberServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("UTF-8");
MemberVO vo = new MemberVO();
String name = request.getParameter("name");
String phone =request.getParameter("phone");
String account = request.getParameter("account");
String passwd = request.getParameter("passwd");
if(name.equals("")|| name==null)
name= "없음";
if(phone.equals("")|| phone==null)
phone= "없음";
if(account.equals("")|| account==null)
account= "없음";
if(passwd.equals("")|| passwd==null)
passwd= "없음";
vo.setAccount(account);
vo.setName(name);
vo.setPhone(phone);
vo.setPasswd(passwd);
request.setAttribute("member", vo);
request.getRequestDispatcher("/jspsrc/memberView.jsp").forward(request, response);
}
}
4)memberVO
package vo;
public class MemberVO {
private String name;
private String phone;
private String account;
private String passwd;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
}
'Java' 카테고리의 다른 글
[MAVEN] git에서 import할때 src/main/java 사라졌을 경우 (0) | 2022.02.05 |
---|---|
[Java Dynamic Web Project ]압축 폴더 import하기 (0) | 2022.01.06 |
[JAVA]Date와 SimpleDateFormat으로 간단하게 시간 표시하기 (0) | 2022.01.03 |
[Chapter 10] Object클래스 (0) | 2021.12.15 |
[Chapter08]객체지향 프로그래밍2 (0) | 2021.12.14 |