Struts2 동적 지정 결과

Jsp 반문 페이지
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
  </head>
  
  <body>
	    
	                 set get  
	<ol>
		<li><a href="user/user?type=1">  success</a></li>
		<li><a href="user/user?type=2">  error</a></li>
	</ol>
  </body>
</html>
struts.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>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<constant name="struts.ognl.allowStaticMethodAccess" value="true"></constant>
    <package name="login" extends="struts-default" namespace="/user">
        <action name="user" class="com.lbx.action.UserAction">
        	<result>${r}</result>
        </action>
    </package>
    
</struts>
Useraction 코드
package com.lbx.action;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class UserAction extends ActionSupport{
	private int type;
	private String r;
	public int getType() {
		return type;
	}
	public void setType(int type) {
		this.type = type;
	}
	public String getR() {
		return r;
	}
	public void setR(String r) {
		this.r = r;
	}
	@Override
	public String execute() throws Exception {
		if(type==1){r="/success.jsp";}
		if(type==2){r="/error.jsp";}
		return SUCCESS;
	}
	
	
}
success.jsp와 error.jsp

좋은 웹페이지 즐겨찾기