- GUI
- Windows API tutorial
- Introduction to Windows API
- Windows API main functions
- System functions in Windows API
- Strings in Windows API
- Date & time in Windows API
- A window in Windows API
- First steps in UI
- Windows API menus
- Windows API dialogs
- Windows API controls I
- Windows API controls II
- Windows API controls III
- Advanced controls in Windows API
- Custom controls in Windows API
- The GDI in Windows API
- PyQt4 tutorial
- PyQt5 tutorial
- Qt4 tutorial
- Introduction to Qt4 toolkit
- Qt4 utility classes
- Strings in Qt4
- Date and time in Qt4
- Working with files and directories in Qt4
- First programs in Qt4
- Menus and toolbars in Qt4
- Layout management in Qt4
- Events and signals in Qt4
- Qt4 Widgets
- Qt4 Widgets II
- Painting in Qt4
- Custom widget in Qt4
- The Breakout game in Qt4
- Qt5 tutorial
- Introduction to Qt5 toolkit
- Strings in Qt5
- Date and time in Qt5
- Containers in Qt5
- Working with files and directories in Qt5
- First programs in Qt5
- Menus and toolbars in Qt5
- Layout management in Qt5
- Events and signals in Qt5
- Qt5 Widgets
- Qt5 Widgets II
- Painting in Qt5
- Custom widget in Qt5
- Snake in Qt5
- The Breakout game in Qt5
- PySide tutorial
- Tkinter tutorial
- Tcl/Tk tutorial
- Qt Quick tutorial
- Java Swing tutorial
- JavaFX tutorial
- Java SWT tutorial
- wxWidgets tutorial
- Introduction to wxWidgets
- wxWidgets helper classes
- First programs in wxWidgets
- Menus and toolbars in wxWidgets
- Layout management in wxWidgets
- Events in wxWidgets
- Dialogs in wxWidgets
- wxWidgets widgets
- wxWidgets widgets II
- Drag and Drop in wxWidgets
- Device Contexts in wxWidgets
- Custom widgets in wxWidgets
- The Tetris game in wxWidgets
- wxPython tutorial
- Introduction to wxPython
- First Steps
- Menus and toolbars
- Layout management in wxPython
- Events in wxPython
- wxPython dialogs
- Widgets
- Advanced widgets in wxPython
- Drag and drop in wxPython
- Internationalisation
- Application skeletons in wxPython
- The GDI
- Mapping modes
- Creating custom widgets
- Tips and Tricks
- wxPython Gripts
- The Tetris game in wxPython
- C# Winforms Mono tutorial
- Java Gnome tutorial
- Introduction to Java Gnome
- First steps in Java Gnome
- Layout management in Java Gnome
- Layout management II in Java Gnome
- Menus in Java Gnome
- Toolbars in Java Gnome
- Events in Java Gnome
- Widgets in Java Gnome
- Widgets II in Java Gnome
- Advanced widgets in Java Gnome
- Dialogs in Java Gnome
- Pango in Java Gnome
- Drawing with Cairo in Java Gnome
- Drawing with Cairo II
- Nibbles in Java Gnome
- QtJambi tutorial
- GTK+ tutorial
- Ruby GTK tutorial
- GTK# tutorial
- Visual Basic GTK# tutorial
- PyGTK tutorial
- Introduction to PyGTK
- First steps in PyGTK
- Layout management in PyGTK
- Menus in PyGTK
- Toolbars in PyGTK
- Signals & events in PyGTK
- Widgets in PyGTK
- Widgets II in PyGTK
- Advanced widgets in PyGTK
- Dialogs in PyGTK
- Pango
- Pango II
- Drawing with Cairo in PyGTK
- Drawing with Cairo II
- Snake game in PyGTK
- Custom widget in PyGTK
- PHP GTK tutorial
- C# Qyoto tutorial
- Ruby Qt tutorial
- Visual Basic Qyoto tutorial
- Mono IronPython Winforms tutorial
- Introduction
- First steps in IronPython Mono Winforms
- Layout management
- Menus and toolbars
- Basic Controls in Mono Winforms
- Basic Controls II in Mono Winforms
- Advanced Controls in Mono Winforms
- Dialogs
- Drag & drop in Mono Winforms
- Painting
- Painting II in IronPython Mono Winforms
- Snake in IronPython Mono Winforms
- The Tetris game in IronPython Mono Winforms
- FreeBASIC GTK tutorial
- Jython Swing tutorial
- JRuby Swing tutorial
- Visual Basic Winforms tutorial
- JavaScript GTK tutorial
- Ruby HTTPClient tutorial
- Ruby Faraday tutorial
- Ruby Net::HTTP tutorial
- Java 2D games tutorial
- Java 2D tutorial
- Cairo graphics tutorial
- PyCairo tutorial
- HTML5 canvas tutorial
- Python tutorial
- Python language
- Interactive Python
- Python lexical structure
- Python data types
- Strings in Python
- Python lists
- Python dictionaries
- Python operators
- Keywords in Python
- Functions in Python
- Files in Python
- Object-oriented programming in Python
- Modules
- Packages in Python
- Exceptions in Python
- Iterators and Generators
- Introspection in Python
- Ruby tutorial
- PHP tutorial
- Visual Basic tutorial
- Visual Basic
- Visual Basic lexical structure
- Basics
- Visual Basic data types
- Strings in Visual Basic
- Operators
- Flow control
- Visual Basic arrays
- Procedures & functions in Visual Basic
- Organizing code in Visual Basic
- Object-oriented programming
- Object-oriented programming II in Visual Basic
- Collections in Visual Basic
- Input & output
- Tcl tutorial
- C# tutorial
- Java tutorial
- AWK tutorial
- Jetty tutorial
- Tomcat Derby tutorial
- Jtwig tutorial
- Android tutorial
- Introduction to Android development
- First Android application
- Android Button widgets
- Android Intents
- Layout management in Android
- Android Spinner widget
- SeekBar widget
- Android ProgressBar widget
- Android ListView widget
- Android Pickers
- Android menus
- Dialogs
- Drawing in Android
- Java EE 5 tutorials
- Introduction
- Installing Java
- Installing NetBeans 6
- Java Application Servers
- Resin CGIServlet
- JavaServer Pages, (JSPs)
- Implicit objects in JSPs
- Shopping cart
- JSP & MySQL Database
- Java Servlets
- Sending email in a Servlet
- Creating a captcha in a Servlet
- DataSource & DriverManager
- Java Beans
- Custom JSP tags
- Object relational mapping with iBATIS
- Jsoup tutorial
- MySQL tutorial
- MySQL quick tutorial
- MySQL storage engines
- MySQL data types
- Creating, altering and dropping tables in MySQL
- MySQL expressions
- Inserting, updating, and deleting data in MySQL
- The SELECT statement in MySQL
- MySQL subqueries
- MySQL constraints
- Exporting and importing data in MySQL
- Joining tables in MySQL
- MySQL functions
- Views in MySQL
- Transactions in MySQL
- MySQL stored routines
- MySQL Python tutorial
- MySQL Perl tutorial
- MySQL C API programming tutorial
- MySQL Visual Basic tutorial
- MySQL PHP tutorial
- MySQL Java tutorial
- MySQL Ruby tutorial
- MySQL C# tutorial
- SQLite tutorial
- SQLite C tutorial
- SQLite PHP tutorial
- SQLite Python tutorial
- SQLite Perl tutorial
- SQLite Ruby tutorial
- SQLite C# tutorial
- SQLite Visual Basic tutorial
- PostgreSQL C tutorial
- PostgreSQL Python tutorial
- PostgreSQL Ruby tutorial
- PostgreSQL PHP tutorial
- PostgreSQL Java tutorial
- Apache Derby tutorial
- SQLAlchemy tutorial
- MongoDB PHP tutorial
- MongoDB Java tutorial
- MongoDB JavaScript tutorial
- MongoDB Ruby tutorial
- Spring JdbcTemplate tutorial
- JDBI tutorial
Implicit objects in JSPs
In this part of the JEE tutorials, we will talk about implicit objects in JSP pages. Implicit objects are important objects that are available within scriptlets. Here we will mention some of them.
the out object
Implicit object out is used to write to the output stream. The out object has page scope. A specific out object is available for each JSP page.
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="java.util.List" %> <%@page import="java.util.ArrayList" %> <html> <head> <title>Implicit Out Object</title> <style> * { font-size: 12px; font-family: Verdana } td { border: 1px solid #ccc; padding: 3px } th { border: 1px solid #4B8699; padding: 3px; background: #4B8699; color: white } </style> </head> <body> <h2>Out Object</h2> <%! List authors = new ArrayList(); %> <% if (authors.isEmpty()) { authors.add("Leo Tolstoy"); authors.add("Fiodor Dostoevsky"); authors.add("Emile Zola"); authors.add("Honore de Balzac"); } out.println("<table>"); out.println("<th>"); out.println("Authors"); out.println("</th>"); for (int i = 0; i < authors.size(); i++) { out.println("<tr>"); out.println("<td>"); out.println(authors.get(i)); out.println("</td>"); out.println("</tr>"); } out.println("</table>"); %> </body> </html>
Our code example creates an HTML table. It uses the implicit out parameter.
out.println("<th>"); out.println("Authors"); out.println("</th>");
This code prints a header for the table.
There is another way, how we can print the table—by mixing HTML and Java code.
index.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="java.util.List" %> <%@page import="java.util.ArrayList" %> <html> <head> <title>Implicit Out Object</title> <style> * { font-size: 12px; font-family: Verdana } td { border: 1px solid #ccc; padding: 3px } th { border: 1px solid #4B8699; padding: 3px; background: #4B8699; color: white } </style> </head> <body> <h2>Out Object</h2> <%! List authors = new ArrayList(); %> <% if (authors.isEmpty()) { authors.add("Leo Tolstoy"); authors.add("Fiodor Dostoevsky"); authors.add("Emile Zola"); authors.add("Honore de Balzac"); } %> <table> <th>Authors</th> <% for (int i = 0; i < authors.size(); i++) { %> <tr> <td> <%= authors.get(i) %> </td> </tr> <% } %> </table> </body> </html>
The outcome is the same for both examples.

response object
Object response is used as a reply to the request from the client. This object is seldom used by JSP authors. The response object has page scope. There is one situation, where the response object might be useful. Say we want to rename the URL of one page. But we realize that many people might have bookmarked the page. To overcame this issue, we might use the response object to redirect the request to a new page.
index.jsp
<% response.sendRedirect("target.jsp"); %>
target.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <html> <head> <title>Target JSP Page</title> </head> <body> <h2>Welcome</h2> </body> </html>
When we run the example, we end up with the target.jsp
page.
The request object
We will demonstrate a request object in a simple form. The form is use to send user data to the server for processing.
index.jsp
<html> <head> <title>Form</title> <style> * { font-size: 12px; font-family: Verdana } input { border: 1px solid #ccc } </style> </head> <body> <form method="get" action="book.jsp"> <p> Enter a book name </p> <input type="text" name="bookname"> <input type="submit" value="submit"> </form> </body> </html>
book.jsp
<html> <head> <title>Book</title> <style> * { font-size: 12px; font-family: verdana } </style> </head> <body> <p> You have entered: <%= request.getParameter("bookname") %> </p> </body> </html>
In this example, we have two JSP files. One file is used to enter data. We use a form. The data is sent to the second JSP file, which will simply print the data, we have entered.
<style> * { font-size: 12px; font-family: Verdana } input { border: 1px solid #ccc } </style>
We use some CSS to make our page prettier. We change the font size and family and set a new border for an input HTML tag.
<form method="get" action="book.jsp">
The action parameter specifies the name of the JSP file, which will receive the data we send.
You have entered: <%= request.getParameter("bookname") %>
This line will output the data we entered into the form. The request object encapsulates the data sent by the client.
Next we use an alternative method to deploy the war file.
$ ls books.jsp index.jsp
We have two JSP files.
$ jar -cvf form.war * added manifest adding: books.jsp(in = 197) (out= 151)(deflated 23%) adding: index.jsp(in = 308) (out= 204)(deflated 33%)
We create a web archive.
$ ls books.jsp form.war index.jsp
The web archive has been created.
$ asadmin deploy --user=admin ~/programming/jee/form/form.war
We can use the asadmin tool to deploy the web archive. We provide the user name and the path to the war file. By default, the admin user is called admin and the password is adminadmin.
Command deploy executed successfully.
If everything goes ok, we see this message.
application object
The application
object is available to all clients. It shares data on all application pages. The application object can be used to share data, log messages, track user hits or access server information.
book.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <html> <head> <title>application object</title> <style> * { font-size: 12px; font-family: Verdana } </style> </head> <body> <h2>application object</h2> <p> Resource paths: </p> <%= application.getResourcePaths("/") %> <br> <%= application.getResourcePaths("/WEB-INF") %><br> <%= application.getResourcePaths("/META-INF") %> <p> Server: </p> <%= application.getServerInfo() %> <p> Context path: </p> <%= application.getContextPath() %> </body> </html>
In our example, we print resource paths. These are all paths to resources within the web application. Further we print server information and the context path. Our server is Resin 3.1.3. The context path uniquely identifies the web application in server.

In this chapter, we mentioned JSP implicit objects.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论