Author: jspfuns
By Scott Ferguson
Introduction
Sample Framework: Hello, World
Servlet comments
Display message board
Message board mode
Message board as an application attribute
Message board logic
Conclusion
Introduction
The powerful advantage of JSP is that it separates the business logic of an application from its introduction. In Smalltalk object-oriented terms, JSP encourages MVC (model-view-controller) web applications. JSP classes or beans are models, JSP is the view, and Servlet is the controller.
This example is a simple message board. User logon and message.
It is also available in the Resin demos
Role Implementation
Model A GuestBook of Guests.
View login. jsp for new users
Add. jsp for logged-in users.
Controller GuestJsp, a servlet to manage the state.
Sample Framework: Hello, World
The GuestJsp framework transmits the "Hello, World" string to the login. jsp page. This framework sets up a structure for the message board. The details will be added below.
This example can be viewed after being compiled:
Http: /localhost: 8080/servlet/jsp. GuestJsp
You can see the following page:
Hello, world
The JSP template starts with Servlet processing and passes the processing result to the JSP page for formatting.
Forwarding uses a Servlet 2.1 feature of the ServletContext, getRequestDispatcher (). the request dispatcher lets servlets forward and include any subrequests on the server. it & acute; s a more flexible replacements for SSI between Des. the RequestDispatcher can include the results of any page, servlet, or JSP page in a servlet & acute; s page. guestJsp will use dispatcher. forward () to pass control to the JSP page for formatting.
GuestJsp. java: Skeleton package jsp. GuestJsp;
Import java. io .*;
Import java. util .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
/**
* GuestJsp is a servlet controlling user
* Interaction with the guest book.
*/
Public class GuestJsp extends HttpServlet {
/**
* DoGet handles GET requests
*/
Public void doGet (HttpServletRequest req,
HttpServletResponse res)
Throws ServletException, IOException
{
// Save the message in the request for login. jsp
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.