1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <!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> <h1 align="center">맥주 색깔 선택 화면</h1> <form action="beer.do" method="get"> 맥주의 특정 선택<br /> 색깔 : <select name="color" size="1"> <option>밝은 색 <option>황색 <option>갈색 <option>어두운 색 </select><br /> <br /> <input type="submit" value="선택완료"> </form> </body> </html> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package beer; import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; public class LoginCheckFilter implements Filter { public LoginCheckFilter() { } public void destroy() { } public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest)request; HttpServletResponse httpResponse = (HttpServletResponse)response; HttpSession session = httpRequest.getSession(); //사용자 정보가 담긴 객체에서 세션을 불러온다. if(session == null){//세션이 없으면, 로그인 안한 상태 httpResponse.sendRedirect("loginForm.html"); //loginForm.html로 사용자 화면을 변경한다. } String id = (String)session.getAttribute("ID"); if(id == null){//세션은 있는데 ID값이 없으면, httpResponse.sendRedirect("loginForm.html?ID=nobody"); //loginForm.html로 화면을 변경하면서 nobody를 출력함. } chain.doFilter(request, response); System.out.println("로그인 체크 필터 동작 완료!"); } public void init(FilterConfig fConfig) throws ServletException { } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <% String id = request.getParameter("ID"); String password = request.getParameter("PWD"); String message = ""; if (id.equals("abc") && password.equals("1234")) { session.setAttribute("ID", id); message = "로그인 되었습니다. <br/>"; %> <script> setTimeout("location.href='BeerSelect.html'",3000); </script> <% } else { message = "로그인 되지 않은 아이디 또는 패스워드 입니다.<br/>"; %> <script> setTimeout("location.href='loginForm.html'",3000); </script> <% } %> <!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>Insert title here</title> </head> <body> <%=message%> </body> </html> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | package beer; import java.util.ArrayList; import java.util.List; public class BeerExpert { public List getBrands(String color){ List<String> brands = new ArrayList<String>(); if(color.equals("황색")){ brands.add("누런 맥주"); brands.add("Jack Amber"); brands.add("노란 맥주"); brands.add("Moor"); }else if(color.equals("갈색")){ brands.add("갈색 폭격기"); brands.add("갈색주"); brands.add("North One"); brands.add("Gous Stout"); }else if(color.equals("밝은 색")){ brands.add("칼스"); brands.add("White Beer"); }else{ brands.add("흑맥주"); brands.add("Black Smith"); } return brands; } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | package beer; import java.io.IOException; import java.util.List; import javax.servlet.RequestDispatcher; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class BeerServlet extends HttpServlet { private static final long serialVersionUID = 1L; public BeerServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String color = request.getParameter("color"); BeerExpert be = new BeerExpert(); List beer = be.getBrands(color); String adminAddr = getServletConfig().getInitParameter("Admin Address"); String adminPhone = getServletConfig().getInitParameter("Admin phone"); ServletContext sc = getServletContext(); long totalCount = Long.parseLong(String.valueOf(sc.getAttribute("tatalCount"))); request.setAttribute("COUNT", totalCount); request.setAttribute("BEERS", beer); request.setAttribute("ADMINADDR", adminAddr); request.setAttribute("ADMINPHONE", adminPhone); RequestDispatcher rd = request.getRequestDispatcher("beerResult.jsp"); rd.forward(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <%@ 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>Insert title here</title> </head> <body> <h2>다음 맥주를 추천합니다.</h2> ${BEERS } <BR /> <h3>관리자의 주소</h3> ${ADMINADDR } <BR /> <h3>관리자의 전화번호</h3> ${ADMINPHONE } <BR /> 방문자 수는 ${COUNT } 명 입니다. </body> </html> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | <?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_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>May31_1</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>BeerServlet</display-name> <servlet-name>BeerServlet</servlet-name> <servlet-class>beer.BeerServlet</servlet-class> <init-param> <param-name>Admin Address</param-name> <param-value>서울시 강남구 역삼1동</param-value> </init-param> <init-param> <param-name>Admin phone</param-name> <param-value>010-1111-2222</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>BeerServlet</servlet-name> <url-pattern>/beer.do</url-pattern> </servlet-mapping> <filter> <display-name>LoginCheckFilter</display-name> <filter-name>LoginCheckFilter</filter-name> <filter-class>beer.LoginCheckFilter</filter-class> </filter> <filter-mapping> <filter-name>LoginCheckFilter</filter-name> <url-pattern>/BeerSelect.html</url-pattern> </filter-mapping> </web-app> | cs |
'개발' 카테고리의 다른 글
[안드로이드]Fragment 사용하기 (0) | 2013.11.13 |
---|---|
[java] 스프링 프레임워크란? (0) | 2013.07.15 |
[java] 1부터 50개의 숫자 중에서 25를 골라서 5행 5열에 출력 (0) | 2013.04.15 |
[java] 지비 모터스 자동차 판매 매출 (0) | 2013.04.05 |
[java] 김길동 백화점 물건 구매 (0) | 2013.04.05 |