Do a hands-on JSP starter program (ii): Create a project (JSP)

Source: Internet
Author: User
Tags java web
Create a project

We developed using the Eclipse and Tomcat for the Web server. Eclipse we need to use "Eclipse IDE for Java EE developers" (an IDE tool prepared by Eclipse for Java EE developers) and click here to download the latest version of the website. Tomcat can click here to download the website. The Tomcat installation configuration also requires readers to confidently search Google. Configure the Tomcat Web server in Eclipse.

The configuration is as follows: In the panel below Eclipse, click the right mouse button, then "New"-> "Server", then in the pop-up window: "Apache"-> "Tomcat v8.0 Server"-> "Next". Since I installed the 8.0.41 version of 8.5.11 that was originally updated, this is not configurable in my eclipse, so before downloading Tomcat you need to see which version of Eclipse you can use, or find the latest eclipse. Select the path to install Tomcat in the pop-up window and click Finish. Create a Dynamic Web page project

Create a Dynamic Web Projectin Eclipse: "File"-> "New"-> "other ..."; "Web"-> "Dynamic Web Project"-> click "Next"; Enter the project name-> Select the project path-> Select the servlet 3.1 specification in Dynamic Web module version. -> click "Finish".

After successful creation, you will get the following file directory:

Here you need to talk about a file that is not in a created project:web.xml. This file is called the configuration descriptor, and before the Servlet 2.5 specification, each Java Web project must contain a Web.xml file and must be under Web-inf. Starting with Servlet 3.0, the file is no longer required, but it is usually recommended for retention. The file can be found in the Web-inf folder of the case under the WebApps directory of your Tomcat installation directory, and you can also use the following code directly. Its most basic configuration is as follows:

<?xml version= "1.0" encoding= "UTF-8"?> <web-app version=
"2.5" xmlns= "http://java.sun.com/xml/ns/" 
    Java ee " 
    xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance " 
    xsi:schemalocation=" http://java.sun.com/ Xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
  <display-name></ display-name> 
  <welcome-file-list>
    <!--set up Web applications first in
        order from top to bottom, The index.jsp is accessed first, and if index.jsp does not exist, the index.html is accessed.
    -->
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</ welcome-file>
  </welcome-file-list>
</web-app>

The JSP file we created will be placed directly in the WebContent directory. On the webcontent right, "New"-> "other ..."-> found "JSP File" under the Web to create it. In the JSP file we created, we need to notice the first line of code in the file. This line of code stipulates that the language used is Java (which we will see in other background language development web programs), and the encoding used. In order to support the Chinese display, we need to change "iso-8859-1" to "utf-8". Here's a little trick to make a new JSP file use UTF-8 encoding: in Eclipse's navigation bar, "window"-> "preferences"-> "Web"-> "JSP", and on the right you can see encoding items, We choose "IOS 10646/unicode (UTF-8)".

<%@ page language= "java" contenttype= "text/html; Charset=iso-8859-1 "pageencoding=" Iso-8859-1 "%>

  The JSP(Java Server Page) is a presentation layer technology (presentation layer technology with freemarket, velocity, and tapestry), which is composed of two basic members of the Java EE specification with the servlet. Both are essentially the same, because the JSP must eventually be compiled into a servlet to run. In addition to special situations (such as using <jsp:include> actions, a <jsp:include> action generates a separate servlet class), a generic JSP file generates a servlet class. After running the program, we can \work\catalina\localhost in the Tomcat directory (or the default path for Eclipse. metadata.plugins\org.eclipse.wst.server.core\ TMP0\WORK\CATALINA\LOCALHOST\SIMPLESHOP\ORG\APACHE\JSP), locate the corresponding Java file in the corresponding project directory.

The CSS directories and JavaScript directories and the IMG directories that we need to use after

are all placed in the WebContent directory. It can be understood that the directory is the root directory for our project. So access to the picture can be directly used Access can be.

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.