Building Dynamic Web sites with JSP

Source: Internet
Author: User
Tags expression tomcat linux

First, what is JSP

JSP (JavaServer pages) JSP by the Sun Microsystems Company Advocacy, a number of companies involved in the establishment of a dynamic Web page technology standards, its Web site is http://www.javasoft.com/products/jsp. Adding Java program Fragments (scriptlet) and JSP tags (tag) to the traditional Web page HTML file (*.htm,*.html) forms the JSP Web page (*.jsp). When a Web server encounters a request to access a JSP Web page, it first executes the program fragment in it, and then returns the execution results to the customer in HTML format. Program fragments can manipulate databases, redirect Web pages, and send emails, and so on, which is the functionality required to build dynamic Web sites. All programs operate on the server side, the network sent to the client is only the result of the minimum requirements for customer browsers, can be achieved without plugin, no ActiveX, no Java applets, even without frame. This article will introduce the method of using JSP technology to develop dynamic Web pages, and will briefly analyze the differences between JSP technology and Microsoft's ASP technology.

Second, how to install and start

In order to experiment JSP technology, first need to establish the running environment, this process is quite simple:

1. Download JDK (Java 2 SDK, Standard Edition, v 1.2.2) at http://java.sun.com/jdk/.

2. Download JSWDK (JavaServer Web Development Kit 1.0.1) at http://java.sun.com/products/jsp/. Linux users can download Tomcat 3.0 at ttp://jakarta.apache.org/.

3, installation

In the case of the Windows NT environment, the JDK is installed to run the downloaded Jdk1_2_2-win.exe first, then modify the system environment parameters, add [X:]\jdk1.2.2\bin, and add new environment parameters to the Path parameter classpath=[x:] \jdk1.2.2\lib\tools.jar, where [x:] is the hard drive character (c:, D:, and so on) where the JDK is installed. JSWDK installation only needs to release the Jswdk1_0_1-win.zip with directory to the hard disk root (C:\, d:\ And so on), and then you can find the \jswdk-1.0.1\ directory on your hard disk. If you do not want to keep JSWDK in the future, you can delete this directory, without any system files and registry legacy problems. More detailed installation procedures, as well as installation of JDK and Tomcat under Solaris/unix and Linux, can refer to the installation instructions in the downloaded packages.

4, start

Taking the Windows NT environment as an example, executing startserver.bat in the \jswdk-1.0.1\ directory enables a Web server in JSWDK that supports JSP web technology. To not conflict with existing Web servers (such as IIS, PWS, and so on), the JSWDK Web server uses port 8080. In the browser's address bar type http://localhost:8080 or http://127.0.0.1:8080, if you can see the JSWDK Welcome page on the JSP experimental environment has been completed, you can enter the next experiment. To close the Web server, run Stopserver.bat.

Three, the JSP simple example

The document directory for the Web server contained in JSWDK is \jswdk-1.0.1\webpages by default, and the main document is index.html and index.jsp by default. That is to say, access to http://localhost:8080 equals access \jswdk-1.0.1\webpages\index.html.
With a text editor, such as Notepad in Windows, create a text file hi.jsp, saved in the \jswdk-1.0.1\webpages\ directory, which reads as follows:

<html>
<head>
<title>Hi-JSP实验</title>
</head>
<body>
<%
String Msg = "This JSP test.";
out.print("Hello World!");
%>
<h2><%=Msg%></h2>
</body>
</html>

Figure 1

Typing the Web server in Http://localhost:8080/hi.jsp,JSWDK in the address bar of the browser executes the Java program statements enclosed in <% and%> in the JSP file, where Out.print is outputting the text to the Web page, and the statement <%= variable | The function of an expression%> is to output the value of a variable or expression in a Java scriptlet to a Web page, performing the result as shown in Figure 1. Figure 1 To assign the variable msg as a Chinese string, with <%=%> output, or with Out.print output Chinese string, then in the English version NT4 and Redhat 6.1 under the normal results of the experiment, and in the Chinese NT 4.0 and Chinese 98, it will appear garbled.

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.