Apache Struts: Hello World!(Struts 2.0.14)

https://archive.apache.org/dist/struts/binaries/ 에서 struts-2.0.14-all.zip 파일을 내려받는다.(엄청 오래 걸림 -_-;;)

clip_image001[4]
  • commons-logging-1.0.4.jar
  • freemarker-2.3.8.jar
  • ognl-2.6.11.jar
  • struts2-core-2.0.14.jar
  • xwork-2.0.7.jar

파일을 미리 다른 곳에 빼놓는다.

clip_image002[4]

Dynamic Web Project 만들기

clip_image003[4]

이름을 적고, 다음

clip_image004[4]

web.xml 만들기

clip_image005[4]

/WebContent/WEB-INF/lib 폴더에 위에서 선택한 파일을 붙여 넣는다.

clip_image006[4]

web.xml에 필터를 등록함.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?xml version="1.0" encoding="UTF-8"?>
 
 
<display-name>HelloWorld</display-name>
 
<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>
 
<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>
 
</filter-mapping>
 
</web-app>
clip_image007[4]

이번에는 새 클래스 만들기

clip_image008[4]

대충 적어 준다.

clip_image009[4]

코드를 작성함.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package happy.ch02.example01;
 
//POJO(자바 빈즈)
 
public class HelloWorld {
 
// 아래 3 문장은 읽기 전용 프로퍼티
 
private String message; // 객체의 프로퍼티에 직접 접근 못함
 
public String getMessage() { // 읽기 전용을 위해 getter만 정의
 
return message; // 간접적으로 사용
 
}
 
// 액션 메소드(기본적으로 execute란 이름을 사용한
 
public String execute() throws Exception {
 
this.message = "Hello, World!"; // 비즈니스 로직
 
return "success"; // 리절트 코드
 
}
 
}
clip_image010[4]

이번에는 Other 파일을 만듦.

clip_image011[4]

XML 파일

clip_image012[4]

src 폴더에 만든다.

clip_image013[4]

struts.xml 이라는 이름으로, 위와 같이 작성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<!DOCTYPE struts PUBLIC
 
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 
 
<struts>
 
<package name="example01" extends="struts-default">
 
<action name="HelloWorld" class="happy.ch02.example01.HelloWorld">
 
<result name="success">/HelloWorld.jsp</result>
 
</action>
 
</package>
 
</struts>
clip_image014[4]

이 위치다.(잘못 파일을 지워서 프로젝트를 새로 생성함 ㅠㅠ)

clip_image015[4]

이번에는 JSP 파일. ${message}만 살아 있으면 된다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<%@ 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>${message}</h1>
 
</body>
 
</html>
clip_image016

드디어 된다 ㅠㅠ

(이 화면을 보기까지 1시간 걸림)

이것도 살펴보세요!

WSL 개발 환경 설정

WSL로 개발 환경 설정하는 법 https://learn.microsoft.com/ko-kr/windows/wsl/setup/environment 1. 아래 명령으로 WSL을 설치하고, 리눅스 사용자 이름과 암호 …

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다