JAVA JSP
[JSP] 내가 만든 Class import하기
코더알파카
2020. 4. 7. 00:24
개발환경
OS Windows10
Server Tomcat8.5.x
IDE intelliJ
index.jsp
<%--
Created by IntelliJ IDEA.
User: console
Date: 2020-03-31
Time: 오전 2:50
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="example.HelloWorld" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<%
HelloWorld s = new HelloWorld();
String a = s.sayHelloWorldFrom("123");
out.println(a);
%>
</body>
</html>
HelloWorld.class
package example;
public class HelloWorld {
public String sayHelloWorldFrom(String from) {
String result = "Hello, world, from " + from;
System.out.println(result);
return result;
}
}
파일구조
요약
외부 lib를 import시 반드시 패키지화 되어야한다.
내부 lib가 아닌 직접만든 lib는 다음과 같은 방법으로 최상단에 import한다.
<%@ page import="패키지명.클래스명" %>
ex) <%@ page import="example.HelloWorld" %>