웹사이트 검색

JSP 인터뷰 질문 및 답변


JSP 인터뷰 질문은 Java 인터뷰를 하려는 경우 매우 중요합니다. JSP는 모든 Java EE 웹 애플리케이션의 필수적인 부분이며 최근에 저는 JSP의 다양한 기능에 대해 많은 글을 썼습니다. JSP, JSP 스크립팅의 기초부터 시작하여 JSP 페이지에서 Java 코드를 피하기 위해 JSP 사용자 지정 태그로 끝냈습니다. 살펴볼 수 있는 자습서 중 일부는 다음과 같습니다.

  1. 초보자를 위한 JSP 자습서
  2. JSP 암시적 개체
  3. JSP 지시어
  4. JSP 예외 처리
  5. JSP 작업 태그
  6. JSP EL
  7. JSTL 핵심 태그
  8. JSP 사용자 지정 태그

JSP 인터뷰 질문

  1. JSP란 무엇이며 왜 필요한가요?
  2. JSP 라이프사이클 단계란 무엇입니까?
  3. JSP 라이프사이클 메소드란 무엇입니까?
  4. 재정의할 수 있는 JSP 수명 주기 방법은 무엇입니까?
  5. 클라이언트 브라우저에서 JSP 페이지에 직접 액세스하지 않으려면 어떻게 해야 합니까?
  6. JSP의 다른 유형의 주석은 무엇입니까?
  7. JSP의 스크립틀릿, 표현식 및 선언이란 무엇입니까?
  8. JSP 암시적 개체란 무엇입니까?
  9. JSP 선언에 정의된 메소드에서 JSP 암시적 객체를 사용할 수 있습니까?
  10. 일반 JSP 페이지에서 사용할 수 없는 암시적 객체는 무엇입니까?
  11. PageContext 암시적 개체의 이점은 무엇입니까?
  12. JSP용 초기 매개변수는 어떻게 구성합니까?
  13. JSP에서 스크립팅 요소를 사용하지 않는 이유는 무엇입니까?
  14. JSP 페이지에서 클래스를 정의할 수 있습니까?
  15. JSP 페이지에서 자바 코드나 스크립팅을 비활성화하려면 어떻게 해야 합니까?
  16. JSP 작업 요소 또는 작업 태그를 설명하시겠습니까?
  17. include 지시문과 jsp:include 작업의 차이점은 무엇인가요?
  18. JSP 표현 언어란 무엇이며 이점은 무엇입니까?
  19. JSP EL 암시적 객체란 무엇이며 JSP 암시적 객체와 어떻게 다릅니까?
  20. JSP EL을 사용하여 HTTP 메소드 이름을 얻는 방법
  21. JSP 표준 태그 라이브러리는 무엇이며 몇 가지 사용 예를 제공합니까?
  22. JSTL 태그의 유형은 무엇입니까?
  23. JSP Custom Tag란 무엇이며 구성 요소는 무엇입니까?
  24. JSP 사용자 정의 태그가 필요한 예를 들어 주시겠습니까?
  25. web.xml에서 JSP 표준 태그를 구성할 필요가 없는 이유는 무엇입니까?
  26. JSP 서비스 메소드에서 발생한 예외를 어떻게 처리할 수 있습니까?
  27. JSTL을 사용하여 어떻게 예외를 포착하고 처리합니까?
  28. JSP에서 "
    HTML에 새 줄을 만듭니다\를 어떻게 인쇄합니까?
  29. 배치 설명자에서 jsp-config란 무엇입니까?
  30. JSP에서 EL 표현식 평가를 무시하는 방법은 무엇입니까?
  31. 컨테이너는 언제 여러 JSP/서블릿 개체를 초기화합니까?
  32. JSP 페이지에서 JavaScript를 사용할 수 있습니까?
  33. JSP에서 암시적 세션 생성을 어떻게 방지할 수 있습니까?
  34. JspWriter와 Servlet PrintWriter의 차이점은 무엇입니까?
  35. JSP 기술을 어떻게 확장할 수 있습니까?
  36. 일부 JSP 모범 사례를 제공하시겠습니까?

JSP 인터뷰 질문 및 답변

JSP란 무엇이며 왜 필요한가요?\nJSP는 JavaServer Pages의 약자입니다. JSP는 동적 웹 페이지를 생성하는 Java 서버 측 기술입니다. JSP는 개발자가 HTML과 같은 구문으로 동적 페이지를 만들 수 있도록 도와주는 Servlet 기술의 확장입니다. 우리는 서블릿에서도 사용자 뷰를 생성할 수 있지만 코드가 매우 보기 흉하고 오류가 발생하기 쉽습니다. 또한 웹 페이지의 대부분의 요소는 정적이므로 JSP 페이지가 웹 페이지에 더 적합합니다. 우리는 JSP 페이지에서 비즈니스 로직을 피하고 보기 목적으로만 사용하도록 노력해야 합니다. JSP 스크립팅 요소는 JSP 페이지에서 Java 코드를 작성하는 데 사용할 수 있지만 이러한 요소를 피하고 JSP 작업 요소, JSTL 태그 또는 사용자 정의 태그를 사용하여 동일한 기능을 달성하는 것이 가장 좋습니다. JSP의 또 다른 이점은 대부분의 컨테이너가 JSP 페이지의 핫 배포를 지원한다는 것입니다. JSP 페이지에서 필요한 사항을 변경하고 이전 페이지를 배포 디렉토리의 업데이트된 JSP 페이지로 바꾸면 컨테이너가 새 JSP 페이지를 로드합니다. 프로젝트 코드를 컴파일하거나 서버를 다시 시작할 필요가 없지만 서블릿 코드를 변경하면 전체 프로젝트를 다시 빌드하고 배포해야 합니다. 현재 대부분의 컨테이너가 애플리케이션에 대한 핫 배포 지원을 제공하지만 여전히 JSP 페이지보다 더 많은 작업이 필요합니다.\n\n\nJSP 라이프사이클 단계는 무엇입니까?\nJSP 페이지 코드를 살펴보면 HTML처럼 보이고 Java 클래스처럼 보이지 않습니다. 실제로 JSP 컨테이너는 JSP 페이지를 번역하고 웹 애플리케이션에서 사용되는 서블릿 클래스를 생성합니다. JSP 라이프사이클 단계는 다음과 같습니다.\n\n번역 - JSP 컨테이너는 JSP 페이지 코드를 확인하고 파싱하여 서블릿 소스 코드를 생성합니다. 예를 들어 Tomcat에서는 TOMCAT/work/Catalina/localhost/WEBAPP/org/apache/jsp 디렉토리에서 생성된 서블릿 클래스 파일을 찾을 수 있습니다. JSP 페이지 이름이 home.jsp인 경우 일반적으로 생성되는 서블릿 클래스 이름은 home_jsp이고 파일 이름은 home_jsp.java입니다. 컴파일 - JSP 컨테이너는 이 단계에서 JSP 클래스 소스 코드를 컴파일하고 클래스 파일을 생성합니다.\n클래스 로딩 - 컨테이너는 이 단계에서 클래스를 메모리에 로드합니다.\n인스턴스화 - 컨테이너는 생성된 클래스의 인수 없는 생성자를 호출하여 메모리에 로드하고 인스턴스화합니다.\n초기화 - 컨테이너는 JSP 클래스 개체의 초기화 메서드를 호출하고 배포 설명자에 구성된 초기화 매개변수로 서블릿 구성을 초기화합니다. 이 단계가 끝나면 JSP는 클라이언트 요청을 처리할 준비가 됩니다. 일반적으로 JSP의 변환에서 초기화까지는 JSP에 대한 첫 번째 요청이 올 때 발생하지만 load-on-startup 요소를 사용하는 서블릿처럼 배포 시 로드되고 초기화되도록 구성할 수 있습니다.\n요청 처리 - 이것은 JSP 페이지의 가장 긴 수명 주기이며 JSP 페이지는 클라이언트 요청을 처리합니다. 처리는 다중 스레드이며 서블릿과 유사하며 모든 요청에 대해 새 스레드가 생성되고 ServletRequest 및 ServletResponse 개체가 생성되고 JSP 서비스 메서드가 호출됩니다.\nDestroy - JSP 클래스가 메모리에서 언로드되는 JSP 수명 주기의 마지막 단계입니다. 일반적으로 응용 프로그램이 배포 취소되거나 서버가 종료될 때 발생합니다.

JSP 라이프사이클 메소드란 무엇입니까?

JSP 라이프사이클 메소드는 다음과 같습니다.

  1. jspInit(): 이 메서드는 JspPage에서 선언되며 JSP 컨테이너 구현에 의해 구현됩니다. 이 메소드는 배치 디스크립터에 구성된 구성 매개변수로 초기화하기 위해 JSP 라이프사이클에서 한 번 호출됩니다. JSP 선언 스크립팅 요소를 사용하여 이 메서드를 재정의하여 JSP 페이지에서 사용하려는 리소스를 초기화할 수 있습니다.
  2. _jspService(): 요청 및 응답 객체를 전달하여 각 클라이언트 요청에 대해 JSP 컨테이너에서 호출되는 JSP 메서드입니다. 이 메서드를 재정의할 수 없기 때문에 메서드 이름이 다른 수명 주기 메서드와 구별하기 위해 밑줄로 시작한다는 점에 유의하세요. 모든 JSP 코드는 이 메서드에 포함되며 기본적으로 재정의됩니다. JSP 선언 스크립팅 요소를 사용하여 이를 무시하려고 시도해서는 안 됩니다. 이 메서드는 HttpJspPage 인터페이스에 정의되어 있습니다.
  3. jspDestroy(): 이 메소드는 애플리케이션 또는 컨테이너 종료와 같이 JSP가 메모리에서 언로드될 때 컨테이너에 의해 호출됩니다. 이 메서드는 JSP 수명 주기에서 한 번만 호출되며 JSP 초기화 메서드에서 생성된 리소스를 해제하려면 이 메서드를 재정의해야 합니다.

재정의할 수 있는 JSP 수명 주기 메서드는 무엇입니까?

JSP 선언 스크립팅 요소를 사용하여 jspInit() 및 jspDestroy() 메서드를 재정의할 수 있습니다. JSP 서비스 메소드에서 사용할 공통 자원을 생성하려면 jspInit() 메소드를 오버라이드하고 공통 자원을 해제하려면 jspDestroy() 메소드를 오버라이드해야 합니다.

클라이언트 브라우저에서 JSP 페이지에 직접 액세스하지 않으려면 어떻게 해야 합니까?

We know that anything inside the WEB-INF directory can't be accessed directly in a web application, so we can place our JSP pages in WEB-INF directory to avoid direct access to JSP page from the client browser. But in this case, we will have to configure it in deployment descriptor just like Servlets. The sample configuration is given below code snippet of web.xml file.

```
<servlet>
  <servlet-name>Test</servlet-name>
  <jsp-file>/WEB-INF/test.jsp</jsp-file>
  <init-param>
    <param-name>test</param-name>
    <param-value>Test Value</param-value>
  </init-param>
</servlet>
   
<servlet-mapping>
  <servlet-name>Test</servlet-name>
  <url-pattern>/Test.do</url-pattern>
</servlet-mapping>
```

JSP의 다른 유형의 주석은 무엇입니까?

JSP pages provide two types of comments that we can use:
-   **HTML Comments**: Since JSP pages are like HTML, we can use HTML comments like `<!-- HTML Comment -->`. These comments are sent to client also and we can see it in HTML source. So we should avoid any code level comments or debugging comments using HTML comments.
-   **JSP Comments**: JSP Comments are written using scriptlets like `<%-- JSP Comment --%>`. These comments are present in the generated servlet source code and doesn't sent to client. For any code level or debugging information comments we should use JSP comments.

JSP의 스크립틀릿, 표현식 및 선언이란 무엇입니까?

Scriptlets, Expression and Declaration are scripting elements in JSP page using which we can add java code in the JSP pages. A scriptlet tag starts with `<%` and ends with `%>`. Any code written inside the scriptlet tags go into the `_jspService()` method. For example;

```
<%
Date d = new Date();
System.out.println("Current Date="+d);
%>
```

Since most of the times we print dynamic data in JSP page using _out.print()_ method, there is a shortcut to do this through JSP Expressions. JSP Expression starts with `<%=` and ends with `%>`. `<% out.print("Pankaj"); %>` can be written using JSP Expression as `<%= "Pankaj" %>` Notice that anything between `<%= %>` is sent as parameter to `out.print()` method. Also notice that scriptlets can contain multiple java statements and always ends with semicolon (;) but expression doesn't end with semicolon. JSP Declarations are used to declare member methods and variables of servlet class. JSP Declarations starts with `<%!` and ends with `%>`. For example we can create an int variable in JSP at class level as `<%! public static int count=0; %>`.

JSP 암시적 개체란 무엇입니까?

**JSP implicit objects** are created by container while translating JSP page to Servlet source to help developers. We can use these objects directly in **scriptlets** that goes in service method, however we can't use them in JSP Declaration because that code will go at class level. We have 9 implicit objects that we can directly use in JSP page. Seven of them are declared as local variable at the start of _\_jspService()_ method whereas two of them are part of _\_jspService()_ method argument that we can use.
1.  out Object
2.  request Object
3.  response Object
4.  config Object
5.  application Object
6.  session Object
7.  pageContext Object
8.  page Object
9.  exception Object
10.  JSP Implicit Objects Example

JSP Implicit Objects.19에서 각각에 대해 자세히 읽어보십시오. ### JSP 선언에 정의된 메소드에서 JSP 암시적 객체를 사용할 수 있습니까?

No we can't because JSP implicit objects are local to service method and added by JSP Container while translating JSP page to servlet source code. JSP Declarations code goes outside the service method and used to create class level variables and methods and hence can't use JSP implicit objects.

일반 JSP 페이지에서 사용할 수 없는 암시적 개체는 무엇입니까?

JSP exception implicit object is not available in normal JSP pages and it's used in JSP error pages only to catch the exception thrown by the JSP pages and provide useful message to the client.

PageContext 암시적 개체의 이점은 무엇입니까?

JSP pageContext implicit object is instance of javax.servlet.jsp.PageContext abstract class implementation. We can use pageContext to get and set attributes with different scopes and to forward request to other resources. pageContext object also hold reference to other implicit object. This is the only object that is common in both JSP implicit objects and in JSP EL implicit objects.

JSP용 초기화 매개변수는 어떻게 구성합니까?

We can configure init params for JSP similar to servlet in web.xml file, we need to configure JSP init params with servlet and servlet-mapping element. The only thing differs from servlet is jsp-file element where we need to provide the JSP page location.

JSP에서 스크립팅 요소를 사용하지 않는 이유는 무엇입니까?

JSP pages are mostly used for view purposes and all the business logic should be in the servlet or model classes. We should pass parameters to JSP page through attributes and then use them to create the HTML response in JSP page. Most part of the JSP page contains HTML code and to help web designers to easily understand JSP page and develop them, JSP technology provides action elements, JSP EL, JSP Standard Tag Library and custom tags that we should use rather than scripting elements to bridge the gap between JSP HTML part and JSP java part.

JSP 페이지에서 클래스를 정의할 수 있습니까?

It's not a good practice though, but we can define a class inside a JSP Page. Below is the sample code for this:

```
<%!
private static class NestedClass { //static is better because Servlet is multi-threaded
  private final int num = 0;
  public int getNum() {
    return num;
  }
}
%>
```

Or

```
<%      
    class Person { 
        //this will go inside method body, so can't be public
    }
%>
```

JSP 페이지에서 자바 코드나 스크립팅을 비활성화하려면 어떻게 해야 합니까?

We can disable scripting elements in JSP pages through deployment descriptor configuration like below.

```
<jsp-config>
	<jsp-property-group>
		<url-pattern>*.jsp</url-pattern>
		<scripting-invalid>true</scripting-invalid>
	</jsp-property-group>
</jsp-config>
```

Above URL-pattern will disable scripting for all the JSP pages but if you want to disable it only for a specific page, you can give the JSP file name itself.

JSP 작업 요소 또는 작업 태그를 설명하시겠습니까?

JSP action elements or action tags are HTML like tags that provide useful functionalities such as working with Java Bean, including a resource, forwarding the request and to generate dynamic XML elements. JSP action elements always starts with jsp: and we can use them in JSP page directly without the need to import any tag libraries or any other configuration changes. Some of the important action elements are jsp:useBean, jsp:getProperty, jsp:setProperty, jsp:include and jsp:forward. Read more in details about these at [**JSP Action Elements**](/community/tutorials/jsp-action-tags-jsp-usebean-include-forward).

include 지시문과 jsp:include 작업의 차이점은 무엇입니까?

The difference between JSP include directive and include action is that in include directive the content to other resource is added to the generated servlet code at the time of translation whereas with include action it happens at runtime. Another difference is that in JSP include action, we can pass params to be used in the included resource with `jsp:param` action element but in JSP include directive we can't pass any params. When the included resource is static such as header, footer, image files then we should use include directive for faster performance but if the included resource is dynamic and requires some parameters for processing then we should use include action tag.

JSP Expression Language는 무엇이며 이점은 무엇입니까?

Most of the times we use JSP for view purposes and all the business logic is present in servlet code or model classes. When we receive client request in the servlet, we process it and then add attributes in request/session/context scope to be retrieved in JSP code. We also use request params, headers, cookies and init params in JSP to create response views. We can use scriptlets and JSP expressions to retrieve attributes and parameters in JSP with java code and use it for view purpose. But for web designers, java code is hard to understand and that’s why JSP Specs 2.0 introduced Expression Language (EL) through which we can get attributes and parameters easily using HTML like tags. Expression language syntax is `${name}` and we can use EL implicit objects and EL operators to retrieve the attributes from different scopes and use them in JSP page. Read more about JSP EL with example program at [**JSP EL Tutorial**](/community/tutorials/jsp-expression-language-el-example-tutorial).

JSP EL 암시적 객체는 무엇이며 JSP 암시적 객체와 어떻게 다릅니까?

JSP Expression Language provides many implicit objects that we can use to get attributes from different scopes and parameter values. Note that these are different from JSP implicit objects and contains only the attributes in given scope. The only common implicit object in JSP EL and JSP page is pageContext object. Below table provides a list of implicit object in JSP EL.

| JSP EL Implicit Objects | Type | Description |
| --- | --- | --- |
| pageScope | Map | A map that contains the attributes set with page scope. |
| requestScope | Map | Used to get the attribute value with request scope. |
| sessionScope | Map | Used to get the attribute value with session scope. |
| applicationScope | Map | Used to get the attributes value from application scope. |
| param | Map | Used to get the request parameter value, returns a single value |
| paramValues | Map | Used to get the request param values in an array, useful when request parameter contain multiple values. |
| header | Map | Used to get request header information. |
| headerValues | Map | Used to get header values in an array. |
| cookie | Map | Used to get the cookie value in the JSP |
| initParam | Map | Used to get the context init params, we can't use it for servlet init params |
| pageContext | pageContext | Same as JSP implicit pageContext object, used to get the request, session references etc. example usage is getting request HTTP Method name. |

JSP EL을 사용하여 HTTP 메소드 이름을 얻는 방법은 무엇입니까?

We can use pageContext JSP EL implicit object to get the request object reference and use dot operator to get the HTTP method name in JSP page. The JSP EL code for this will be `${pageContext.request.method}`.

JSP 표준 태그 라이브러리는 무엇이며 몇 가지 사용 예를 제공합니까?

JSP Standard Tag Library or JSTL is more versatile than JSP EL or Action elements because we can loop through a collection or escape HTML tags to show them like text in response. JSTL is part of the Java EE API and included in most servlet containers. But to use JSTL in our JSP pages, we need to download the JSTL jars for your servlet container. Most of the times, you can find them in the example projects and you can use them. You need to include these libraries in the project WEB-INF/lib directory. These jars are container specific, for example in Tomcat, we need to include jstl.jar and standard.jar jar files in the project build path. Read more about JSTL tags with example program at [**JSTL Tutorial**](/community/tutorials/jstl-tutorial-jstl-tags-example).

JSTL 태그의 유형은 무엇입니까?

Based on the JSTL functions, they are categorized into five types.
1.  Core Tags - Core tags provide support for iteration, conditional logic, catch exception, url, forward or redirect response etc.
2.  Formatting and Localization Tags - These tags are provided for formatting of Numbers, Dates and i18n support through locales and resource bundles.
3.  SQL Tags - JSTL SQL Tags provide support for interaction with relational databases such as Oracle, MySql etc.
4.  XML Tags - XML tags are used to work with XML documents such as parsing XML, transforming XML data and XPath expressions evaluation.
5.  JSTL Functions Tags - JSTL tags provide a number of functions that we can use to perform common operation, most of them are for String manipulation such as String Concatenation, Split String etc.

JSP Custom Tag는 무엇이며 구성 요소는 무엇입니까?

Sometimes JSP EL, Action Tags and JSTL tags are not enough and we might get tempted to write java code to perform some operations in JSP page. Fortunately JSP is extendable and we can create our own custom tags to perform certain operations. We can create JSP Custom Tags with following components:
-   JSP Custom Tag Handler
-   Creating Tag Library Descriptor (TLD) File
-   Deployment Descriptor Configuration for TLDWe can add custom tag library in JSP page using taglib directive and then use it.

JSP 사용자 정의 태그가 필요한 예를 들어 보시겠습니까?

Let’s say we want to show a number with formatting with commas and spaces. This can be very useful for user when the number is really long. So we want some custom tags like below: `<mytags:formatNumber number="123456.789" format="#,###.00"/>` Based on the number and format passed, it should write the formatted number in JSP page, for the above example it should print 123,456.79 We know that JSTL doesn’t provide any inbuilt tags to achieve this, so we will create our own custom tag implementation and use it in the JSP page. Read above example implementation at [**JSP Custom Tag**](/community/tutorials/jsp-custom-tags-example-tutorial).

web.xml에서 JSP 표준 태그를 구성할 필요가 없는 이유는 무엇입니까?

We don't need to configure JSP standard tags in web.xml because the TLD files are inside the META-INF directory of the JSTL jar files. When container loads the web application and finds TLD files inside the META-INF directory of the JAR file, it automatically configures them to be used directly in the application JSP pages. All we need to do it to include it in the JSP page using taglib directive.

JSP 서비스 메소드에서 발생한 예외를 어떻게 처리할 수 있습니까?

To handle exceptions thrown by the JSP page, all we need is an error page and define the error page in JSP using page directive. To create a JSP error page, we need to set the page directive attribute isErrorPage value to true, then we can access exception implicit object in the JSP and use it to send a customized error message to the client. We need to define exception and error handler JSP pages in the deployment descriptor like below.

```
<error-page>
	<error-code>404</error-code>
	<location>/error.jsp</location>
</error-page>

<error-page>
	<exception-type>java.lang.Throwable</exception-type>
	<location>/error.jsp</location>
</error-page>
```

Read more with example program at [**JSP Exception Handling**](/community/tutorials/jsp-exception-handling-jsp-error-page).

JSTL을 사용하여 어떻게 예외를 포착하고 처리합니까?

We can use JSTL Core tags c:catch and c:if to catch exception inside the JSP service method and process it. c:catch tag catches the exception and wraps it into the exception variable and we can use c:if condition tag to process it. Below code snippet provide sample usage.

```
<c:catch var ="exception">
   <% int x = 5/0;%>
</c:catch>
 
<c:if test = "${exception ne null}">
   <p>Exception is : ${exception} <br />
   Exception Message: ${exception.message}</p>
</c:if>
```

Notice the use of JSP EL in the `c:if` condition.

JSP에서 \
HTML에 새 줄 생성\을 어떻게 인쇄합니까?

We can use c:out escapeXml attribute to escape the HTML elements so that it get's shown as text in the browser, for this scenario we will write code like below.

```
<c:out value="<br> creates a new line in HTML" escapeXml="true"></c:out>
```

배포 설명자에서 jsp-config는 무엇입니까?

jsp-config element is used to configure different parameters for JSP pages. Some of it's usage are:
-   Configuring tag libraries for the web application like below.
    
    ```
    <jsp-config>
    		<taglib>
    			<taglib-uri>https://journaldev.com/jsp/tlds/mytags</taglib-uri>
    			<taglib-location>/WEB-INF/numberformatter.tld</taglib-location>
    		</taglib>
    </jsp-config>
    ```
    
-   We can control scripting elements in JSP pages.
-   We can control JSP Expression Language (EL) evaluation in JSP pages.
-   We can define the page encoding for URL pattern.
-   To define the buffer size to be used in JSP page out object.
-   To denote that the group of resources that match the URL pattern are JSP documents, and thus must be interpreted as XML documents.

JSP에서 EL 표현식 평가를 무시하는 방법은 무엇입니까?

We can ignore EL evaluation in JSP page by two ways.
1.  Using page directive as `<%@ page isELIgnored="true" %>`
2.  Configuring in web.xml - better approach when you want to disable EL evaluation for many JSP pages.
    
    ```
    <jsp-config>
    	<jsp-property-group>
    		<url-pattern>*.jsp</url-pattern>
    		<el-ignored>true</el-ignored>
    	</jsp-property-group>
    </jsp-config>
    ```

컨테이너는 언제 여러 JSP/서블릿 개체를 초기화합니까?

If we have multiple servlet and servlet-mapping elements in deployment descriptor for a single servlet or JSP page, then container will initialize an object for each of the element and all of these instances will have their own ServletConfig object and init params. For example, if we configure a single JSP page in web.xml like below.

```
<servlet>
  <servlet-name>Test</servlet-name>
  <jsp-file>/WEB-INF/test.jsp</jsp-file>
  <init-param>
    <param-name>test</param-name>
    <param-value>Test Value</param-value>
  </init-param>
</servlet>
   
<servlet-mapping>
  <servlet-name>Test</servlet-name>
  <url-pattern>/Test.do</url-pattern>
</servlet-mapping>
   
<servlet>
  <servlet-name>Test1</servlet-name>
  <jsp-file>/WEB-INF/test.jsp</jsp-file>
</servlet>
   
<servlet-mapping>
  <servlet-name>Test1</servlet-name>
  <url-pattern>/Test1.do</url-pattern>
</servlet-mapping>
```

그런 다음 두 URI 패턴을 사용하여 동일한 JSP 페이지에 액세스할 수 있고 둘 다 고유한 초기화 매개변수 값을 갖게 됩니다.65. ### JSP 페이지에서 JavaScript를 사용할 수 있습니까?

Yes why not, I have seen some developers getting confused with this. Even though JSP is a server-side technology, it's used to generate a client-side response and we can add javascript or CSS code like any other HTML page.

JSP에서 암시적 세션 생성을 어떻게 방지할 수 있습니까?

By default JSP page creates a session but sometimes we don’t need session in JSP page. We can use JSP page directive session attribute to indicate compiler to not create session by default. It’s default value is true and session is created. To disable the session creation, we can use it like below.

```
<%@ page session="false" %>
```

JspWriter와 Servlet PrintWriter의 차이점은 무엇입니까?

PrintWriter is the actual object responsible for writing the content in response. JspWriter uses the PrintWriter object behind the scene and provide buffer support. When the buffer is full or flushed, JspWriter uses the PrintWriter object to write the content into response.

JSP 기술을 어떻게 확장할 수 있습니까?

We can extend JSP technology with custom tags to avoid scripting elements and java code in JSP pages.

JSP 모범 사례를 제공하시겠습니까?

Some of the JSP best practices are:
1.  Avoid scripting elements in JSP pages. If JSP EL, action elements and JSTL not serve your needs then create custom tags.
2.  Use comment properly, use JSP comments for code level or debugging purpose so that it's not sent to client.
3.  Avoid any business logic in JSP page, JSP pages should be used only for response generation for client.
4.  Disable session creation in JSP page where you don't need it for better performance.
5.  Use page, taglib directives at the start of JSP page for better readability.
6.  Proper use of jsp include directive or include action based on your requirements, include directive is good for static content whereas include action is good for dynamic content and including resource at runtime.
7.  Proper exception handling using JSP error pages to avoid sending container generated response incase JSP pages throw exception in service method.
8.  If you are having CSS and JavaScript code in JSP pages, it's best to place them in separate files and include them in JSP page.
9.  Most of the times JSTL is enough for our needs, if you find a scenario where it's not then check your application design and try to put the logic in a servlet that will do the processing and then set attributes to be used in JSP pages.

중요한 JSP 인터뷰 질문을 놓친 경우 알려주십시오. 앞으로 목록에 더 추가할 예정입니다.