DB를 생성한건 아니고 DB가 있다고 생각하자~~
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="tutorial" extends="struts-default"> <action name="Form"> <result>Form.jsp</result> </action> <action name="Insert" class="DAO.DBHelper" method="insert"> <result name="success">/success.jsp</result> <result name="fail">/fail.jsp</result> </action> </package> </struts>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>스트러츠 2번째</title> </head> <body> Form.jsp<br/> <form action="Insert.action" method="get"> 아이디: <input type="text" name="id" size="10" required="required"> <br/> 비번 : <input type="password" name="pw" size="10" required="required"> <br/> 좋아하는 동물: <input type="radio" name="animal" value="dog" checked="checked">강아지 <input type="radio" name="animal" value="cat">고양이 <input type="radio" name="animal" value="bird">새 <br/><input type="submit" value="보내기"> </form> </body> </html>
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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>struts study start</display-name> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> <!-- 사이트.com/abc.jsp --> </filter-mapping> <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> </web-app>
package DAO; public class DBHelper { public DBHelper(){ System.out.println("DBHelper default Constructor"); } public String execute(){ return "success"; } public String insert(){ //db에 값을 입력하는 메서드가 될것이다 System.out.println("insert"); try{ //db에 저장하는 소스가 여기에 여러줄 있다고 생각하자 System.out.println("db에 저장중입니다"); System.out.println("db에 저장중입니다"); }catch(Exception e){ return "fail"; } return "success"; } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>Insert title here</title> </head> <body> 성공 성공 </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!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=UTF-8"> <title>Insert title here</title> </head> <body> fail fail fail </body> </html>
※DBHelper.java 에서 리턴 값을 fail 로 주면 fail.jsp가 실행된다~
'Struts2 > 2012.04월 강좌(MySQL)' 카테고리의 다른 글
1일차 interceptor (0) | 2012.06.04 |
---|---|
1일차 한글 깨짐 현상 (0) | 2012.06.04 |
1일차 랜덤한 이미지 (0) | 2012.06.04 |
1일차 기본 페이지 설정 및 요청 (0) | 2012.06.04 |
1일차 파일 포함시키기 (0) | 2012.06.04 |