How to build a Java Web project manually __web

Source: Internet
Author: User
Tags java web


Internship six months to find that they did not manually build a Java Web project; One of the most basic things about Java Web development.

, and began to build a. There's a lot of small problems in the middle.

The first is the directory structure of the entire Web project:

Project Name: Eg:mywebtest

Below the project contains subdirectories: Web-inf,page;

Here is the need to note that Web-inf need to capitalize;

Below Web-inf need to include: Classes, LIB, two directories and Web.xml files

Classes: main storage of compiled. class files

LIB: Store the jar packages you need to rely on; The simplest project needs to be Jstl.jar, Standard.jar these two packages

Web.xml: Configuration file;

Example of a configuration file:

<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi= 
"Http://www.w3.org/2001/XMLSchema-instance" " 
    xmlns=" Http://java.sun.com/xml/ns/javaee "xmlns:web=" http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd " 
    xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    id= "webapp_id" version= "2.5" > 
    <display-name>MyWebTest</display-name>
    <servlet >
	<servlet-name>HandleServer</servlet-name>
	<servlet-class> com.xc.test.handleserver</servlet-class>
    </servlet>
    <servlet-mapping>
	< servlet-name>handleserver</servlet-name>
	<url-pattern>/do</url-pattern>
	</ servlet-mapping>
    <welcome-file-list>
	<welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>
Write a Servlet.java

Use Javac Servlet.java to compile Java to get. class files. Store the compiled. class file under Web-inf;

Tomcat configuration:

The first thing to do is to add tomcat to the environment variable (this internet check)

Second, configure the virtual directory:

Server.xml in the Conf directory under Tomcat

Add in Host label

<content path= "/mywebtests" docbase= "G:\Gillion\gillion-tool\tomcat-6.0.16\tomcat-6.0.16\webapps\MyWebTests"/ >
This configuration means that the path that Tomcat recognizes is docbase; the access address we entered in the browser is http://localhost:8080/MyWebTests

If you want to configure your tomcat, you need to edit the server.xml in conf to configure the listening port

If you want to set login tomcat username password you need to modify the Tomcat-uers.xml under Conf

eg

<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<tomcat-users>
  <role rolename= ' manager '/>
  <role rolename= "Tomcat"/>
  <role rolename= "admin"/> <role rolename=
  "Role1"/>
  < User Username= "Tomcat" password= "Tomcat" roles= "Tomcat"/>
  <user username= "Both" password= "Tomcat" roles= " Tomcat,role1 "/>
  <user username= haha" password= "haha" roles= "Admin,manager"/> <user "username="
  Role1 "password=" Tomcat "roles=" Role1 "/>
</tomcat-users>
The next thing to do is run your tomcat ...

Then enter the address in your browser: http://localhost:8080/MyWebTests








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.