Java JSP implementation of Dynamic Web page

Source: Internet
Author: User

Dynamic page, plainly, is based on certain information (conditions) to change the content presented to the user.

A certain amount of information mentioned here usually refers to the information entered by the user in a form.

Let's look at a common user login interface.

Here we can see a total of three pages, login interface, login successful interface, login failure interface.

However, in order to implement the login interface to jump to two branches, there will be an empty text file, for the page

Jumps provide a direction (judging).

Business logic:

First 4 pages, demo.html (Login interface), login.jsp (judgment), login_success.jsp (successful interface), login_failure.jsp

(Failed interface).

Login interface Form Action property points to login.jsp, after the user clicks the Submit (Login) button, requests to the server (request)

Login.jsp received the request and then began to analyze:

1<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "2pageencoding= "Utf-8"%>3<%4Request.setcharacterencoding ("UTF-8");5String username= request.getparameter ("username");//Get username value6String Password = request.getparameter ("Password");//Get Password value7 if("admin". Equals (username) && "admin". Equals (password)) {8Session.setattribute ("username", username);//Keep username values in the session for subsequent page calls9Request.getrequestdispatcher ("login_success.jsp"). Forward (request, response);//ForwardingTen}Else{ OneResponse.sendredirect ("login_failure.jsp");//Redirect Request A } -%>

This session means that the session will expire from the time you log in to logout, which is why you have logged into a website and browsed

Multi-page or log-in status, and after a long time (the default is 30min) will drop the line.

Java JSP implements Dynamic Web page

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.