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>
<package name="hi" extends="struts-default"
namespace="/" >
<action name="LoginForm" >
<result>/login/LoginForm.jsp</result>
</action>
<!-- LoginCheck.action?userId=xxx&userPw=yyy -->
<action name="LoginCheck" class="service.LoginCheck">
<result>/login/LoginSuccess.jsp</result>
</action>
</package>
</struts>
index.jsp<%@ 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>Index Page</title>
</head>
<body>
인덱스 페이지
<jsp:forward page="/login/LoginForm.jsp"></jsp:forward>
</body>
</html>
web.xml<?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>
<init-param>
<description>한글인코딩하기, FilterDispatcher실행중에
struts.i18n.encoding의 값을 찾아서 셋팅합니다
</description>
<param-name>struts.i18n.encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</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>
LoginForm.jsp<%@ 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> LoginForm.jsp </title>
</head>
<body>
LoginForm.jsp <br />
<form action="LoginCheck.action" method="get">
userId : <input type="text" name="userId"> <br/>
userPw : <input type="text" name="userPw"> <br/>
<input type="submit" value="보내기" >
</form>
</body>
</html>
LoginSuccess.jsp<%@ 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>LoginSuccess</title>
</head>
<body>
LoginSuccess.jsp <br/>
객체.getUserId() 메서드가 호출됩니다. <br/>
user Id : ${userId} / userPw : ${userPw } / <br/>
</body>
</html>
LoginCheck.javapackage service;
public class LoginCheck {
String userId;
String userPw;
public LoginCheck(){
System.out.println("LoginCheck 객체 생성");
}
public String execute(){
System.out.println("execute");
return "success";
}
// 자동으로 호출됩니다
public void setUserId(String userId){
System.out.println("setUserId");
this.userId=userId;
}
public void setUserPw(String userPw) {
System.out.println("setUserPw");
this.userPw = userPw;
}
public String getUserPw() {
System.out.println("getUserPw");
return userPw;
}
public String getUserId() {
System.out.println("getUserId");
return userId;
}
}