Servlet入门

Posted faded828x

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Servlet入门相关的知识,希望对你有一定的参考价值。

Tomcat初次使用

技术图片

 

//a.html
<!
DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>a</title> </head> <body> <form action="http://localhost:8080/abc/hello" method="get"> <input type="submit"> </form> </body> </html>
//web.xml
<?
xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" version="4.0"> <servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>com.WebTest01.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> </web-app>
//index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    This is Faded828x‘s first index.jsp page!
  </body>
</html>
//HelloServlet.java
import
javax.servlet.*; import java.io.IOException; public class HelloServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doGet"); } @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { System.out.println("doPost"); } }

 

以上是关于Servlet入门的主要内容,如果未能解决你的问题,请参考以下文章

Servlet入门总结及第一个Servlet程序

Servlet入门总结及第一个Servlet程序

Servlet入门总结及第一个Servlet程序 (转载)

Servlet快速入门

Atom编辑器入门到精通 Atom使用进阶

java web 开发入门 --- tomcat/servlet/jsp