servlet development techniques, creation, and configuration of servlet, Web. XML configuration

Source: Internet
Author: User

Direct, no nonsense!!!

First: First, in the Eclipse Package Explorer, the right mouse button, select the "new"/servlet command in the popup shortcut menu, enter the package and class name of the new servlet in the popup dialog box, and click Next.

I choose Default, Next

Still default, Next

Note that when creating a Web project, it is important to note that, for example, select the On-XML button, because the servlet needs to configure Web. XML for this file, Web. xml under Web-inf this file

The second arrow has a square bracket in front of it, so you can automatically create the Web. xml file by ticking it.

 1 package Com.ningmeng; 2 3 Import java.io.IOException; 4 Import Java.io.PrintWriter; 5 6 Import Javax.servlet.ServletException; 7 Import Javax.servlet.annotation.WebServlet; 8 Import Javax.servlet.http.HttpServlet; 9 Import javax.servlet.http.httpservletrequest;10 Import javax.servlet.http.httpservletresponse;11/**13 * servlet Implementation class FirstServlet14 */15 @WebServlet ("/firstservlet") public class Firstservlet extends HttpServlet {1      7 private static final long Serialversionuid = 1l;18/**20 * @see Httpservlet#httpservlet () 21 */22 public Firstservlet () {27 super (); +//TODO auto-generated constructor stub25}26 (/**) * @see Httpservlet#doget (httpservletrequest request, httpservletresponse response) */30 protected void Doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {//TODO A Uto-generated Method Stub32 Response.setconteNttype ("text/html"); Response.setcharacterencoding ("GBK"); PrintWriter out=response.getwriter (); 35         Out.print ("<HTML>"); Out.println ("

 1 <?xml version= "1.0" encoding= "UTF-8"?> 2 <web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id=" webapp_id "version=" 3.0 "> 3 <display-name>web02</ Display-name> 4 <welcome-file-list> 5 <welcome-file>index.html</welcome-file> 6 <welcome -file>index.htm</welcome-file> 7 <welcome-file>index.jsp</welcome-file> 8 <welcome-file&gt ;d efault.html</welcome-file> 9 <welcome-file>default.htm</welcome-file>10 <welcome-file>d       Efault.jsp</welcome-file>11 </welcome-file-list>12 <servlet>13 <!--declaring a Servlet object-->14 <servlet-name>firstservlet</servlet-name>15 <!--The previous sentence specifies the name of the Servlet object-->16 <servlet-cl     Ass>com.ningmeng.firstservlet</servlet-class>17  <!--The previous sentence specifies the full location of the Servlet object, including the package name and class name-->18 </servlet>19 <servlet-mapping>20 <!--mapping servlet- ->21 <servlet-name>firstservlet</servlet-name>22 <!--<servlet-name> with top <Servlet> label Signed <servlet-name> elements should not be named-->23 <url-pattern>/firsetservlet</url-pattern>24 <!-- The previous sentence is used to map access URLs-->25 </servlet-mapping>26 </web-app>

Run the effect as shown

servlet development techniques, creation, and configuration of servlet, Web. XML configuration

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.