JSP basic Syntax--Example Walkthrough

Source: Internet
Author: User

Basic Grammar Summary: <% @page >,<% @include >,<jsp:include>,<jsp:forward>

Plus database operations, you can develop a dynamic web.

Database script:

/*======================= using MLDN database =======================*/ Usemldn;/*======================= Deleting the user data table =======================*/DROP TABLE IF EXISTS User ;/*======================= Creating a User data table =======================*/CREATE TABLE User(useridVARCHAR( -)PRIMARY KEY, nameVARCHAR( -) not NULL, PasswordVARCHAR( +) not NULL) ;/*======================= inserting test data =======================*/INSERT  into User(Userid,name,password)VALUES('Admin','Administrator','Admin') ;

Login.htm:

&LT;HTML&GT;&LT;HEAD&GT;&LT;TITLE&GT;WWW.MLDNJAVA.CN,MLDN High-end Java training </title>User Login</td> </tr> <tr> <td> login id:</td> &LT;TD&G T;<input type= "text" name= "id" ></td> </tr> <tr> <td> Login Secret            Yards:</td> <td><input type= "password" name= "password" ></td> </tr>                    <tr> <td colspan= "2" > <input type= "Submit" value= "Login" >    <input type= "reset" value= "reset" > </td> </tr> </table> </form></center></body>

LOGIN_CHECK.JSP:

<% @page contenttype= "text/html" pageencoding= "GBK"%><%@ pageImport= "Java.sql.*"%&GT;&LT;HTML&GT;&LT;HEAD&GT;&LT;TITLE&GT;WWW.MLDNJAVA.CN,MLDN high-end Java training </title>//define connection constants for several databases     Public Static FinalString dbdriver = "Org.gjt.mm.mysql.Driver" ;  Public Static FinalString Dburl = "JDBC:MYSQL://LOCALHOST:3306/MLDN" ;  Public Static FinalString DBUSER = "root" ;  Public Static FinalString Dbpass = "linda0213" ;%><%Connection Conn=NULL;//Database ConnectionPreparedStatement pstmt =NULL;//Database preprocessing OperationsResultSet rs =NULL;//query to process result sets    BooleanFlag =false;//Save TagString name =NULL;//Save real name%><%Try{%><%Class.forName (Dbdriver); Conn=drivermanager.getconnection (Dburl,dbuser,dbpass); String SQL= "SELECT name from User WHERE userid=?" and password=? " ; Pstmt=conn.preparestatement (SQL); Pstmt.setstring (1,request.getparameter ("id")) ; Pstmt.setstring (2,request.getparameter ("Password")) ; RS= Pstmt.executequery ();//Enquiry    if(Rs.next ()) {//If you have data, you can performFlag =true;//indicates successful landingName = rs.getstring (1) ; }    %><%}Catch(Exception e) {e.printstacktrace ();}finally{    Try{rs.close ();        Pstmt.close ();    Conn.close (); } Catch(Exception e) {}}%><%if(flag) {//Landing Success%> <jsp:forward page= "login_success.jsp" > <jsp:param name= "uname" value= "<%=name%>"/&G        T </jsp:forward><%    } Else{//Login Failed%> <jsp:forward page= "login_failure.htm"/><%    }%></center></body>

LOGIN_SUCCESS.JSP:

<% @page contenttype= "text/html" pageencoding= "GBK"%>

Login_failure.htm:

<HTML><HEAD><TITLE>WWW.MLDNJAVA.CN,MLDN High-end Java training </title>

JSP basic Syntax--Example Walkthrough

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.