Java JSP (original Creative hand can be entered)

Source: Internet
Author: User

one, the same programming way JSP and Asp.

the app needs to make a simple website, and a few user promotion links, so involved in the development of the web, originally wanted to use ASP directly yesterday, but then abandoned the idea, because the data access interface is used by the Java servlet, Initially want to directly use static HTML page +servlet+ajax way to do, although in the Web site development for a variety of languages are common, but there is a drawback, binding data this piece is very complex, so still try to find a two JSP case to see, if more complex than the previous way, Directly in the previous way, the following case, the sense of JSP this programming before the use of asp, a bit different is the asp. if the front-end binding data from the inside of the page, the database operation is the internal execution after the return value of the front end of the binding, But JSP is not the same, JSP data access this block and HTML in a page layer, in fact, feel the same way, JSP this block is more advanced than the asp, but the net uses such a way to do programming when not many, only to calculate it a incidental function, then I will mainly say that the technology of this piece.

second, jsp

use JSTL do database operation, need to add two libraries, jstl, standard, download These two libraries from the internet, directly copy into Tomcat Lib folder, the role of these two libraries, Jstl responsible for the operation of the database this block, Standard is the use of JSTL in the label required library, standard is equivalent to use Jstl auxiliary, and here to pay attention to, I am in the Mac OS development, directly in the official download of the two libraries of the package will be error, unable to find the Jstl required label Helper class, If you make an error directly from the official download of the combo jar, you can download the Jstl and standard into the Tomcat Lib on the Internet separately.

1<%@ page language= "java"Import= "java.util.*" contenttype= "text/html; Charset=utf-8 "2pageencoding= "UTF-8"%>3<%@ pageImport= "java.io.*,java.util.*,java.sql.*"%>4<%@ pageImport= "javax.servlet.http.*,javax.servlet.*"%>5 6<!--introducing Database Operations library--7<%@ taglib uri= "http://java.sun.com/jsp/jstl/core" prefix= "c"%>8<%@ taglib uri= "http://java.sun.com/jsp/jstl/sql" prefix= "sql"%>9 Ten<! DOCTYPE HTML public "-//w3c//dtd HTML 4.01 transitional//en" "http://www.w3.org/TR/html4/loose.dtd" > one  a   - - the<title>jsp Load demo</title> - -<body> -<!--database name-- +<sql:setdatasource var= "projectdatabase" driver= "com.mysql.jdbc.Driver" -Url= "jdbc:mysql://120.25.172.21:3306/projectdatabase?useunicode=true&characterencoding=utf8" +user= "root" password= "123456"/> a<!--database name-- at<sql:query datasource= "${projectdatabase}" var= "result" > -SELECT * from InfoSheet limit 0,15; -</sql:query> -   -<table border= "1" width= "100%" > -<tr> in<th>i d</th> -<th> title </th> to<th> content </th> +<th> Release Time </th> -</tr><!--loops the returned data collection to the row of the table-- the<c:foreach var= "row" items= "${result.rows}" > *<tr> $<!--fetch the field value returned by the database--Panax Notoginseng<td><c:out value= "${row.id}"/></td> -<td><c:out value= "${row.infotitle}"/></td> the<td><c:out value= "${row.infocontent}"/></td> +<td><c:out value= "${row.publishtimes}"/></td> a</tr> the</c:forEach> +</table> -   $</body> $

Java JSP (original Creative hand can be entered)

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.