Getting Started with JSP

Source: Internet
Author: User
Tags character set contains expression include variables variable valid apache tomcat
JS 1 JSP (JavaServer Pages) Introduction: In today's world, the popular Internet application development mainly include: asp,php,cgi,jsp ... And many other schemes, technical advantages and disadvantages, but the JSP with its simple and easy to learn, cross-platform characteristics, in many programs unique, in a few years has formed a complete set of norms, and widely used in E-commerce and other fields. In the domestic JSP now has been more extensive attention
2 How to quickly grasp the jsp:jsp is actually a JSP definition of some tags and Java program segments, as well as the mix of HTML files. So, if you want to master JSP must first have a certain understanding of HTML (or how to design a Web page), and then, you must have the basis of Java program (to know JSP is based on the Java language), Finally, some of the necessary knowledge of the JSP logo (it lets you know how to use the Java language and HTML group to synthesize the complete JSP), and this article we mainly introduce the JSP identification and the grammar rule. So it is best to have a little understanding of HTML and the Java language, if you have not learned that there is no relationship, the following introduction will let you have a more intuitive JSP to understand.
3 experience simple and easy to learn jsp:jsp simple and easy to learn, if you have the basis of HTML, to learn it is very easy, do not believe? First take a JSP program for you to see (Simple and classic helloword.jsp):
<%page language= "java"% >
< html>
< head >
< Title>hello world!</title>
< body bgcolor= "#FFFFFF" >
<%string msg= "JSP Example";//define String Object
Out.println ("Hello world!"); %>
<%=msg%> <!-display variable value->
</body>
After running, the output string on the window Hello world! JSP Example, how, a look at it, indeed very simple, except for the "<% >" logo, the others are ordinary hypertext, if you have the basis of hypertext, a look at it, but he and the hypertext is a little different, that is to join the "<% > "Identification, the use of the logo is a Java program, by which to control the display of dynamic data, and directly output to the location embedded in the identifier, the entire structure is quite intuitive, and later if the page changed, the modification has become very easy." As for the identification of the first line of the program, we can not take care of him at the moment, in the end, we will make a corresponding introduction to this kind of grammar.
Read the above JSP program, you should also have a bit of JSP understand it, yes, learning JSP is not a difficult thing, and later, you will feel more and more of the advantages of JSP, his cross-platform features in the Internet development Program is unique, Because JSP technology is built on top of the Java language, many of his features and applications are from the Java language, so if you want to learn JSP, you need to have the basis of Java programming (on the Java language, I do not introduce here, you can refer to the corresponding books, to recommend: "JAVA2 program Design "(Tsinghua University Press))
4 jsp start from scratch:
(a) Download the JDK (Java Development Kit) from the www.java.sun.com and install it, now assume that c:\jdk1.3 B builds the JSP runtime environment: To make the JSP run, you first build the JSP runtime environment.
The main application Server software we use now is WebLogic application Server,apache Tomcat,allarie Jrun. WebLogic is now the market's highest share of a server software, powerful, configuration is also very simple, as a commercial application of the server is a good choice, but as a beginner application, the proposal is not good, because this is business software, need money. JRun is a Allarie company developed by the server software, but also has a relatively high reputation, and WebLogic is also a good choice, but also commercial software. Beginners, or find a cheaper (preferably not money:), Tomcat is your best choice, he is a free server software, and his source code can be free, when you have a deep understanding of it, you can freely expand to fit your own needs, although the configuration is a bit cumbersome, But the above are so many advantages, it is our well-deserved best choice. Here we will take Tomcat as an example, to introduce you to the Win2000 JSP environment configuration:
1 First, download tomcat from the Apache website (http://java.apache.org), downloading a. zip file (jakarta-tomcat.zip), unzip it to your directory, and assume C:\tomcat.
2 Enter Tomcat directory, find Startup.bat file, open edit. Precede the line call Tomcat start with two lines: Set Tomcat_home=c:\tomcat and set java_home=c:\jdk1.3 Note: c:\jdk1.3 is the jdk1.3 installation location.
3 then right click on "My Computer", select Properties. Open advanced options in System Properties, click "Environment Variables", and add two variables classpath and path in both user variables and system variables, and their values are: Classpath value C:\jdk1.3\bin\tools.jar; The value of C:\jdk1.3\lib\dt.jar path is c:\jdk1.3\bin;c:\jdk1.3
4 Execute Jakarta-tomcat\bin\startup.bat, you will see an open Tocmat startup window,
5 Open the browser, enter: http://localhost:8080, return to see the main Tomcat page
c) Introduction to the basic syntax of JSP:
I. Comment statement: "<%--comment--% >" will skip this identity at compile time;
Ii. inserting a valid program segment:<% code% >
Iii. defining global properties in a JSP file:
<%@ page
[language= "Java"]//declaring the type of scripting language
[extends= "Package.class"]//indicates the full name of the Java class to be added to JSP compilation, but use it sparingly, which limits the ability of the JSP to compile.
[import= ' {package.class/package.*}, ... '] List of Java packages that need to be imported
[session= "True/false"]//Set whether the customer needs HTTP session
The size of the [buffer= "none/8kb/sizekb"]//buffer is used by the out object to process the output of the JSP to the client browser
[autoflush= "True/false"]//Set if the buffer overflows, if the output needs to be forced, if its value is defined as true (the default), the output is normal, if it is set to false, if this buffer overflows, can cause an unexpected error to occur. If you set the buffer to none, you cannot set the AutoFlush to False.
[isthreadsafe= "True/false"]//sets whether the JSP file can be used by multiple threads. The default value is true, that is, the JSP can handle requests from multiple users at the same time, and if set to false, a JSP can only process one request at a time
[info= "text"]///A text in the execution JSP will be verbatim added to the JSP, you can use the Servlet.getservletinfo method to retrieve it.
[errorpage= "Relativeurl"]//Set whether this page is an error page, and if set to True, you can use the exception object
[contenttype= "MimeType] [; Charset=characterset] "/" text/html; Charset=iso-8859-1 "]//Set MIME type. The default MIME type is: text/html, the default character set is Iso-8859-1
[iserrorpage= "True/false"]%>
IV. Contains a file: "<%@ include file=" Relativeurl "%>", which can be inserted (statically) at compile time;
V. contains an expression: "<%= expression%>" Displays the value of the expression at run time;
VI. Statement variable: "<%!" Declaration; [Declaration;] + .. % > "such as" <%!int i;% > "
Vii. Create a bean instance and set its properties: ""; Class Property: Sample An object from one class; ID property: Indicates the reference name of this class object; Scope property: The scope of the bean's existence and the valid range of the ID variable name. If page is only valid for this page class (the class object will be re-created the next time the page is called); if it is a session, the class object is created once, for example, if it is only once, and if the class is always valid for application , and only once (equivalent to static amount)
d) Tomcat's JSP routines are described:
<!--Copyright (c) 1999 the Apache Software Foundation. All rights
Reserved.
Number Guess Game
Written by Jason Hunter < Jasonh@kasoftware.com&gt, CTO, K&a Software http://www.servlets.com-->
<%@ page import = "num. Numberguessbean "%>
<! -Imported Java Package->
< Jsp:usebean id= "numguess" class= "num". Numberguessbean "scope=" session "/>
<! -Creates an object and sets its application name to Numguess and declares that the object is always valid during session validity-->
< html>
< head>
< Title>number guess</title>
< body bgcolor= ' white ' >
< font size=4>
<% if (numguess.getsuccess ()) {%>//Calling Numberguessbean object Getsuccess method
congratulations! You got it.
And after just
<%= numguess.getnumguesses ()%>
tries.< p>
<% numguess.reset (); %>
Care to < a href= "numguess.jsp" >try again?
<%} else if (numguess.getnumguesses () = 0) {%> Welcome to the number Guess game.
I ' m thinking of a number between 1 and 100.
< form method=get>
What ' s your guess?
< input Type=text name=guess>
< input type=submit value= "Submit" >
</form>
<%} else {%>//
Good guess, but nope. Try < b>
<%= numguess.gethint ()%></b>.
have made <%= numguess.getnumguesses ()%> guesses.< p>
I ' m thinking of a number between 1 and 100.
< form method=get> What ' s your guess?
< input Type=text name=guess>
< input type=submit value= "Submit" >
</form> <%}%>
</FONT>
</body>
From the example we can see that JSP is through the logic of the program to control the display of the page, through the program to get the dynamic properties of the display.
5) Related website introduction
A) www.java.sun.com
b) www.servlets.com
c) www.21icsearch.com/aspfans/jspfans/default.jsp
D) http://java.apache.org

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.