Struts2/기본(Oracle)
struts2 Redirect
Bohemian life
2012. 6. 27. 16:09
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>