ArticleslgStudy

science

Jakarta Server Pages

Jakarta Server Pages is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Jakarta Server Pages rather than just read about it. In short: Jakarta Server Pages (JSP; formerly JavaServer Pages) is a collection of technologies that helps software developers create dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun Microsystems, JSP is similar to PHP and ASP, but uses the Java programming language.

Jakarta Server Pages — main illustration
Jakarta Server Pages — illustration

Key takeaways

  • Jakarta Server Pages belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Jakarta Server Pages to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Jakarta Server Pages from memory before moving on to harder problems.

Reference excerpt

Jakarta Server Pages (JSP; formerly JavaServer Pages) is a collection of technologies that helps software developers create dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun Microsystems, JSP is similar to PHP and ASP, but uses the Java programming language. To deploy and run Jakarta Server Pages, a compatible web server with a servlet container, such as Apache Tomcat or Jetty, is required.

Overview

Architecturally, JSP may be viewed as a high-level abstraction of Jakarta Servlets. JSPs are translated into servlets at runtime, therefore JSP is a Servlet; each JSP servlet is cached and re-used until the original JSP is modified. Jakarta Server Pages can be used independently or as the view component of a server-side model–view–controller design, normally with JavaBeans as the model and Java servlets (or a framework such as Apache Struts) as the controller. This is a type of Model 2 architecture. JSP allows Java code and certain predefined actions to be interleaved with static web markup content, such as HTML. The resulting page is compiled and executed on the server to deliver a document. The compiled pages, as well as any dependent Java libraries, contain Java bytecode rather than machine code. Like any other .jar or Java program, code must be executed within a Java virtual machine (JVM) that interacts with the server's host operating system to provide an abstract, platform-neutral environment. JSPs are usually used to deliver HTML and XML documents, but through the use of OutputStream, they can deliver other types of data as well. The Web container creates JSP implicit objects like request, response, session, application, config, page, pageContext, out and exception. JSP Engine creates these objects during translation phase.

Syntax

Directives, scriptlets, and expressions declaration JSPs use several delimiters for scripting functions. The most basic is <% ... %>, which encloses a JSP scriptlet. A scriptlet is a fragment of Java code that runs when the user requests the page. Other common delimiters include <%= ... %> for expressions, where the scriptlet and delimiters are replaced with the result of evaluating the expression, and directives, denoted with <%@ ... %>. Java code is not required to be complete or self-contained within a single scriptlet block. It can straddle markup content, provided that the page as a whole is syntactically correct. For example, any Java if/for/while blocks opened in one scriptlet must be correctly closed in a later scriptlet for the page to successfully compile. This allows code to be intermingled and can result in poor programming practices. Content that falls inside a split block of Java code (spanning multiple scriptlets) is subject to that code. Content inside an if block will only appear in the output when the if condition evaluates to true. Likewise, content inside a loop construct may appear multiple times in the output, depending upon how many times the loop body runs.

Example

Standard JSP Tags

The useBean Tag The JSP useBean tag enables the developer to access and create a Javabean. Although using the useBean tag looks similar to an HTML tag, all JSP tags for JavaBeans use XML syntax. Therefore the code containing the useBean tag is case-sensitive. The useBean tag contains several attributes. The id attribute declares the name that is used for gaining access to the bean. The class attribute declares the package and class for the bean. The scope declares the object responsible for storing the bean. The value for the scope defines the duration for which the bean is available for the rest of the java application to use. The scope can be one of the following four values:

The page scope implies that the bean is located in the implicitly defined PageContext object, and is only available for the current page. By default, all beans have a scope of page. The request scope implies that the bean can be found in the HttpServletRequest object. This bean can be accessed by all other JSPs and servlets that have access to the current request object. The session scope implies that the bean can be found in the HttpSession object. This bean can be accessed by all other JSPs and servlets that have access to the specified HttpSession object. The application scope implies that the bean can be found in the ServletContext object. This bean can be accessed by all other JSPs and servlets that have access to the specified ServletContext object.

The getProperty and setProperty Tags After a bean has been created using the useBean tag, the getProperty and setProperty tags can be used for getting and setting the properties of the bean. The JSP getProperty is used to get the property of created bean. The JSP setProperty tag is used to set the properties for a bean. For the getProperty and setProperty tags, the name attribute is used to specify the bean's name. So the name attribute must match the id attribute provided by the useBean tag.

Expression Language

Version 2.0 of the JSP specification added support for the Expression Language (EL), used to access data and functions in Java objects. In JSP 2.1, it was folded into the Unified Expression Language, which is also used in JavaServer Faces. The JSP Expression Language uses a compact syntax which enables the developer to get attributes and JavaBean properties from a given request object. When using EL, a dollar sign ($) must be added at the beginning of the code. The dollar symbol is followed by an opening brace ({), as well as a closing brace (}). The code is then written between the opening and closing braces.

Example The following is an example of EL syntax: The value of variable in the object javabean is ${javabean.variable}.

Additional tags The JSP syntax adds additional tags, called JSP actions, to invoke built-in functionality. Additionally, the technology allows for the creation of custom JSP tag libraries that act as extensions to the standard JSP syntax. One such library is the JSTL.

Jakarta Standard Tag Library

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Jakarta Server Pages

Start with the simplest possible case. Write down what Jakarta Server Pages claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Jakarta Server Pages before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Jakarta Server Pages ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Jakarta Server Pages

In research
Jakarta Server Pages appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Jakarta Server Pages in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Jakarta Server Pages is common in secondary-school and first-year university syllabi. It links to neighbouring topics Java enterprise platform, Java specification requests, Template engines, so understanding it makes those chapters shorter.
In everyday life
Look for Jakarta Server Pages outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Jakarta Server Pages” →

How to study Jakarta Server Pages in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Jakarta Server Pages means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Jakarta Server Pages out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Jakarta Server Pages in simple terms?

Jakarta Server Pages (JSP; formerly JavaServer Pages) is a collection of technologies that helps software developers create dynamically generated web pages based on HTML, XML, SOAP, or other document types. Released in 1999 by Sun Microsystems, JSP is similar to PHP and ASP, but uses the Java progr…

Why does Jakarta Server Pages matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Jakarta Server Pages?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Jakarta Server Pages.

Tags

  • Java enterprise platform
  • Java specification requests
  • Template engines

Keep exploring