RegisterUser1 (redirect 연습)
package com.ch5.action; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import com.opensymphony.xwork2.Action; public class RegisterUser1 implements Action{ private String userId; @Override public String execute() throws Exception { return SUCCESS; } public String getUserId() { String id=""; try { id =URLEncoder.encode(userId,"utf-8"); }catch(UnsupportedEncodingException e){ e.printStackTrace(); } return id; } public void setUserId(String userId) { this.userId = userId; } }
struts-ch5.xml
<?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="ch5" namespace="/ch5" extends="struts-default"> <!-- redirect --> <action name="register" class="com.ch5.action.RegisterUser1"> <interceptor-ref name="params"/> <result name="success" type="redirect">registerSuccess.jsp?userId=${userId}</result> </action> </package> </struts>
registerForm1.jsp (redirect 연습)
<%@ 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>chain 연습</title> </head> <body> <form action="register.action" method="post"> id:<input type="text" name="userId"><br/> <input type="submit" value="로그인"> </form> </body> </html>
registerSuccess.jsp (redirect 연습)
<%@ 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>redirect 연습</title> </head> <body> <h1>${param.userId}님 환영합니다.</h1> </body> </html>
'Struts2 > 기본(Oracle)' 카테고리의 다른 글
struts2 redirectAction,<global-results/> ? (0) | 2012.06.27 |
---|---|
struts2 chain (0) | 2012.06.27 |
struts2 dispatcher 와 redirect 리절트 타입 (0) | 2012.06.27 |
struts2 리절트의 타입의종류, 체인리절트를 활용한 액션 체인 (0) | 2012.06.27 |
struts2 커스텀 인터페이스 (0) | 2012.06.27 |