JSP Application

Including jsp in html page

В одну JSP-страницу можно вставлять несколько других. Это позволяет определять некоторые общие блоки для всех страниц и использовать их повторно на нескольких страницах JSP.

Для этого применяется специальный тег jsp:include , который может использоваться как обычный html-элемент на страницах JSP.

Определим следующий проект.

include in JSP

Допустим, у нас есть файл header.html с простейшим кодом:

 

Hello JSP

В данном случае здесь определен обычный код html.

Также пусть в проекте будет определен файл footer.jsp со следующим содержимым:

Copyright ©Simon & Schuster, Inc. 2002.

В данном случае мы определили два файла, которые представляют соответственно условный хедер и условный футер — части стандартной веб-страницы.

И также определим в проекте файл index.jsp со следующим кодом:

       

Main Content 1

Main Content 2

Main Content 3

С помощью тега jsp:include содержимое обоих файлов вставляется в данную jsp-страницу. Атрибут page указывает на адрес вставляемого файла. Причем это может быть и обычная html-страница, и jsp-файл.

При обращении к странице index.jsp мы сможем увидеть на странице содержимое вставляемых файлов:

Источник

JSP Include

JSP Include

The JSP has a different set of directives for the client or user messages to the JSP containers it provides the global level information’s through about the single or particular JSP pages. And also JSP directives are the special kind of instructions to the JSP containers to translate the JSP codes into the java servlet codes. In the JSP life cycle, translation is one of the phases for the transformation of the codes process based on the user or project requirements. The include is one of the JSP directives for including the data contents related to any kind of resources with different extensions like JSP, HTML, or any text files. The include tag includes the page resources into the translation phase at the required time.

Web development, programming languages, Software testing & others

The basic syntax of tags in the JSP web page files is as follows.

The above code is the basic syntax for the include directive in the html page which is also added the JSP tags which is helpful to include other files for navigating the web applications flow in the project.

How does JSP Include?

  • The JSP includes directives also the set of messages or data to the JSP containers it provides the access like globally so we can view the page in the entire through the world in the browser, particularly in the specific web application. After the include directive entered in the page it moves to the translation phase for converting the codes from JSP into the servlet. We can include the HTML, PHP, XML,JSP, etc it includes any files with different extensions that are already created or yet to be created in the web project.
  • They include also one of the action tags like added the different sets of extension files into the current JSP file or page. The included file resources also it can be any static page for JSP,HTML, or java servlet. We can also include the arguments in the particular values for the specific resources file its also be included in the include tag. Using tag we can add the parameters or arguments in the file. If we use the include in the header page whatever the changes we make to include in the files it is not be reflected in the application but if we use the include in the inside the page that is the action time its will reflected the changes in the included files.
  • While Accessing the JSP directives in the more number of times somewhere is not update the time when we use the tomcat application server it reflects the changes but the container won’t check the included files timestamp also not updated but include directive can include only static page contents, values are assigned in the property file it must be path and file names files exist otherwise file not found exception occurred at run time the files extension may be any types like .html,.jsp,.js, etc.I suppose we have a servlet back end code in our application it may not be included in the include header tag when we include the same servlet in the tag we get the exception like file not found error at the run time. But when we include the servlet in the action tag format the include action tag accepts not only the static page contents it also supports dynamic web page contents. This inaction tag format it supports the requested time interval if it exceeds the server timeout error will be shown and also JSP page contents do not affect the main page of the web applications it includes and shown the output of the included JSP pages.
  • When compared to the include tag as the directive as well as action scenarios in directive files include static format only and also files are changed randomly if we use common codes in the snippet that we can reuse the multiple pages. The include directive code is the reusability JSP page also translates the source codes at only once so it will be better to include the file resources as static.

Examples to Implement JSP Include

Below are the examples mentioned:

Example #1

"ISO-8859-1"%>       

Welcome To My Domain

JSP Include - 1

Example #2

  

Sample

Welcome To My Domain

Welcome user:

JSP Include - 2

Example #3

        

Demo

Welcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My Domain Welcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My Domain Welcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My Domain Welcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My DomainWelcome To My Domain Welcome To My DomainWelcome To My DomainWelcome To My Domain Welcome To My DomainWelcome To My Domain Welcome To My Domain

Thank you Welcome user:

JSP Include - 3

The above examples we will use the include tag in both actions and directive method in the JSP we can add the calendar function for more use.

Conclusion

The JSP include directive and action tags are two different types for translate the JSP codes into the JSP containers we can add all other extension files in the single web page for work in the navigation for web applications.

This is a guide to JSP Include. Here we discuss an introduction to JSP Include with appropriate syntax, working and examples to implement. You can also go through our other related articles to learn more –

500+ Hours of HD Videos
15 Learning Paths
120+ Courses
Verifiable Certificate of Completion
Lifetime Access

1000+ Hours of HD Videos
43 Learning Paths
250+ Courses
Verifiable Certificate of Completion
Lifetime Access

1500+ Hour of HD Videos
80 Learning Paths
360+ Courses
Verifiable Certificate of Completion
Lifetime Access

3000+ Hours of HD Videos
149 Learning Paths
600+ Courses
Verifiable Certificate of Completion
Lifetime Access

All in One Software Development Bundle 3000+ Hours of HD Videos | 149 Learning Paths | 600+ Courses | Verifiable Certificate of Completion | Lifetime Access

Financial Analyst Masters Training Program 1000+ Hours of HD Videos | 43 Learning Paths | 250+ Courses | Verifiable Certificate of Completion | Lifetime Access

Источник

JSP include action tag – JSP Tutorial

Include action tag is used for including another resource to the current JSP page. The included resource can be a static page in HTML, JSP page or Servlet. We can also pass parameters and their values to the resource which we are including. Below I have shared two examples of , one which includes a page without passing any parameters and in second example we are passing few parameters to the page which is being included.

1) Include along with parameters.

2) Include of another resource without sharing parameters.

Relative_URL_of_Page would be the page name if the page resides in the same directory where the current JSP resides.

Example 1: without parameters

In this example we will use action tag without parameters. As a result the page will be included in the current JSP page as it is:

    index.jsp Page 
Page2.jsp 
This is the content of Page2.jsp page

Content of Page2.jsp has been appended in the index.jsp.

IncludeAction-output

Example 2: Use of along with

I’m using action here along with for passing parameters to the page which we are going to include.

    

This is index.jsp Page

    

Hello this is a display.jsp Page

UserID:
Password is:
User Name:
Age:

As you can see that the content of display.jsp has been included in index.jsp. Also, the parameters we have passed are displaying correctly in the included page.

include-action-with-parameters-output

Let us know if you have any doubts and questions regarding the topic. We will be happy to assist you!!

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

Источник

Читайте также:  Search string python file
Оцените статью