HOME JSP 서블릿(Servlet)

Package Explorer

  • Views

    프로젝트 Package Explorer 폴더구조
  • 화면영상

Java,class

package controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
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 model.Customer;
import service.CustomerService;
/**
* Servlet implementation class DoLogin
*/
@WebServlet("/doLogin")
public class DoLogin extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public DoLogin() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String customerId = request.getParameter("customerId"); //get customerId 받기

// 로그인 처리부분
CustomerService service = new CustomerService(); //CustomerService.class 로딩
Customer customer = service.findCustomer(customerId);
request.setAttribute("customer", customer);

// JSTL 태그 List customers = new ArrayList<>();
customers.add(new Customer("id06", "kkk", "k@ff.ac.kr"));
customers.add(new Customer("id07", "lll", "l@ff.ac.kr"));
customers.add(new Customer("id08", "ppp", "p@ff.ac.kr"));

request.setAttribute("customerList", customers);

String page;
if(customer == null)
page = "/view/error.jsp";
else
page = "/view/success.jsp";
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
dispatcher.forward(request, response);
}
}
package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Home
*/
@WebServlet("/home")
public class Home extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Home() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String action = request.getParameter("action");
String page = null;
if(action.equals("login"))
page = "/view/loginform.jsp";
else if(action.equals("help"))
page = "/view/help.jsp";
else
page = "/view/error.jsp";
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
dispatcher.forward(request, response);
}

}

package model;

public class Customer {

private String id;
private String name;
private String email;

public Customer(String id, String name, String email) {
this.id = id;
this.name = name;
this.email = email;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

}
package service;

import java.util.HashMap;
import java.util.Map;

import model.Customer;

public class CustomerService {

private Map customers;

public CustomerService() {
customers = new HashMap();
addCustomer(new Customer("id01", "한홍", "a@goodsweb.kr"));
addCustomer(new Customer("id02", "찬오", "b@goodsweb.kr"));
addCustomer(new Customer("id03", "완홍", "c@goodsweb.kr"));
addCustomer(new Customer("id04", "심심", "d@goodsweb.kr"));
addCustomer(new Customer("id05", "토톡", "e@goodsweb.kr"));
}
public void addCustomer(Customer customer) {
customers.put(customer.getId(), customer);
}

public Customer findCustomer(String id) {
if(id != null) {
return (customers.get(id.toLowerCase()));
}
else
return null;
}
}
< %@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html>
< head>
< meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
< title>오류< /title>
< /head>
< body>
< h3>< a href="/stone/index.jsp">홈< /a> > 오류< /h3>< br>
오류페이지

< /body>
< /html>
< %@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html>
< head>
< meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
< title>도움말 페이지< /title>
< /head>
< body>
< h3>< a href="/stone/index.jsp">홈< /a> > 도움말< /h3>
도움말 페이지
< /body>
< /html>
< %@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html>
< head>
< meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
< title>로그인 < /title>
< /head>
< body>v < h3>< a href="/stone/index.jsp">홈< /a> > 로그인폼< /h3>
< form action="/stone/doLogin" method="get">
아이디 ID : < input type="text" name="customerId" /> < input type="submit" value="로그인"/>< br>< br>< br>
id01,
id02,
id03,
id04,
id05 < br>
< /form>
< /body>
< /html>
< %@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
< %@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

< !-- //
EL (표현언어)
JSTL (표준태그 라이브러리)
-->

< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html>
< head>
< meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
< title>회원정보< /title>v < /head>
< body>
< h3>< a href="/stone/index.jsp">홈< /a> > 로그인 > 회원정보< /h3>
< %-- JSP Expression Language --%>
< ul>
< li>Id: ${customer.id}< /li>
< li>Name: ${customer.name}< /li>
< li>Email: ${customer.email}< /li>
< /ul>

< %-- JSTL 태그라이브러리 --%>
< table style="border: 1px solid red; padding: 10px;">
< c:forEach var="customer" items="${customerList}">
< tr>
< td>${customer.id }< /td>
< td>${customer.name }< /td>
< td>${customer.email }< /td>
< /tr>
< /c:forEach>
< /table>
< /body>
< /html>
< ?xml version="1.0" encoding="UTF-8"?>
< web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

< !-- 시작페이지 설정 -->
< welcome-file-list>
< welcome-file>index.html< /welcome-file>
< welcome-file>index.jsp< /welcome-file>
< welcome-file>default.jsp< /welcome-file>
< /welcome-file-list>
< /web-app>
< %@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
< !DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
< html>
< head>
< meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
< title>메인페이지< /title>
< /head>
< body>
< h3>< a href="/stone/index.jsp">홈< /a> < /h3>
메인페이지
< p>
< a href="/stone/home?action=login"> login page < /a>
< /p>
< p>
< a href="/stone/home?action=help"> help page < /a>
< /p>
< /body>
< /html>


4명  IP : 18.116.♡.117
001 3.♡.51.3 개발팁
(/bbs/board.php?bo_table=tip&sca=HTML%26CSS)
002 141.♡.61.111 오류안내 페이지
(/bbs/login_check.php)
003 52.♡.144.199 전체검색 결과
(/bbs/search.php?sfl=wr_subject%7C%7Cwr_content&sop=and&stx=)
004 18.♡.62.45 와글팡 - android - 웹,앱
(/bbs/board.php?bo_table=develop&wr_id=56)

접속자
  • 오늘 : 201
  • 어제 : 409
  • 최대 : 874
  • 전체 : 401,659

검색로봇(Robots) 최근 방문시간
  • GOOGLE : 5시간 전
  • BING : 17시간 전
  • NAVER : 1일 전
  • DAUM : 3일 전

ETH : 0x8abf3B748ab78828AE07685e4fd53d1a606f18D3



페이스북 네이버 블로그 굿스웹 쇼핑몰 네이버 카페 굿스웹 트위터 굿스웹 티스토리 Google Play