Servlet Video-Developing the first Java Web (simplest Java Web program)

Source: Internet
Author: User
Tags java web

Web projects have directory structure requirements

The web-info folder is a servlet specification that must be named

There are also directory structure requirements under Web-info, such as

Xml

The servlet is an interface with 5 methods that must be implemented

To implement the Java Web, you must implement these 5 methods destroy () Getservletconfig () Getservletinfo () init (servletconfig config) service (servletrequ EST req,servletresponse Res)

The following code is output to the browser window

1 ImportJavax.servlet.Servlet;2 ImportJavax.servlet.ServletConfig;3 Importjavax.servlet.ServletException;4 Importjavax.servlet.ServletRequest;5 ImportJavax.servlet.ServletResponse;6 Importjava.io.IOException;7 ImportJava.io.PrintWriter;8 9  Public classWelcomeservletImplementsServletTen { One      Public voidInit (servletconfig config)throwsservletexception A       { -          -     } the  -      Public voidService (ServletRequest request,servletresponse response)throwsservletexception,ioexception -     { -         +PrintWriter out=Response.getwriter (); -Out.print ("123123"); +     } A  at      Public voiddestroy () {} -      PublicString Getservletinfo () {return NULL;} -      PublicServletConfig Getservletconfig () {return NULL;} -      -}

Configuration XML

1 <?XML version= "1.0" encoding= "Iso-8859-1"?>2 <Web-appxmlns= "Http://xmlns.jcp.org/xml/ns/javaee"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"4 xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee5 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "6 version= "3.1">7 8 <servlet>9 <Servlet-name>Thisisservletname</Servlet-name>Ten <Servlet-class>Welcomeservlet</Servlet-class> One </servlet> A  - <servlet-mapping> - <Servlet-name>Thisisservletname</Servlet-name> the <Url-pattern>/aaa</Url-pattern> - </servlet-mapping> -  - </Web-app>

Servlet Video-Developing the first Java Web (simplest Java Web program)

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.