J2EE—解析Servlet处理过程

    xiaoxiao2021-03-25  104

    Servlet是什么?

    Java Servlet是运行在Web服务器或服务器上的程序,他是作为来自Web浏览器或其他客户端的请求和HTTP服务器上的数据库或应用程序之间的中间层

    自己的理解:服务器端使用servlet解析HTTP协议,它就相当于是浏览器和服务器的桥梁

    举个例子

    浏览器输入用户名和密码,表单提交到服务器

    1.首先明确web程序的目录结构 建立文件夹test_servlet,文件结构如下: test_servlet LoginServlet.html  WEB-INF   classes   lib   web.xml

    2.编辑页面

    <html> <head> <title>登录</title> </head> <body> <br> <br> <form action="loginServlet" > 用户:<input type="type" name="username"><br> 密码:<input type="type" name="password"><br> <input type="submit" value="登录"> </form> </body> </html>

    3.编写web.xml

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>MyServlet</servlet-name> <servlet-class>LoginServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/loginServlet</url-pattern> <!--随便起名字--> </servlet-mapping> </web-app>

    4.详细过程

    转载请注明原文地址: https://ju.6miu.com/read-24731.html

    最新回复(0)