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>
</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>
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>
<!-- tutorial이라는 패키지명을 default로 셋팅
www/index.html/tutorial이 모두 default
-->
<package name="tutorial" extends="struts-default">
<!-- 요청할때 http://localhost:8080/s1.Hello/HelloWorld.action
프로젝트명/패키지명 /액션네임.action
http://localhost:8080/s1.Hello/tutorial/HelloWorld.action
-->
<!-- HelloWorld.action 이라는 요청이 오면 tutorial.HelloWorld 클래스 실행하고
return이 success 라면 root/helloWorld.jsp를 사용자에게 보여준다.
-->
<action name="HelloWorld" class="tutorial.HelloWorld">
<result name="success">/helloWorld.jsp</result>
</action>
<!-- jsp의 mvc모델에서는 컨트롤러 역활을 java클래스가 하는데 에 비해
struts2에서는 컨트롤러 역활을 struts.xml 이 합니다.
-->
</package>
</struts>
HelloWorld.java
package tutorial;
public class HelloWorld {
private String message;
String title;
String text;
String date;
int count;
public String getMessage() {
return message;
}
//java- main ,
//android - onCreate... ,
//jsp:init ,
//struts:execute..
//자동 호출..
public String execute() throws Exception {
this.message = "Hello, World~~~~~~~! <hr/> hi";
// request.setAttribute("message", "밸류~~"); 작업이 발생합니다
/* Item item=DBHelper.select(3);
request.setAttrbitue("item", item);
${item.title}*/
return "success";
}
}
helloWorld.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>Insert title here</title>
</head>
<body>
<h1>
request영역이나/ session영역 / application 영역 / page 영역
에 .. 즉 전에 request.setAttribute("message", "안녕~~~");
<br/>
그런 작업을 누군가가 해주었다.. 그 누군가는 struts..<br/>
${message}
</h1>
</body>
</html>