正文

JSP 中Servlet的自己实现(jsp&servlet)真没想到

文章摘要

这篇文章简要介绍了如何使用JavaServer Pages (Servlets) 和HyperText Precedence (HTTP)的不同请求方式来构建和控制网页。文章通过一个简单的例子展示了如何使用JSP语言创建一个网页,并通过HTTP的GET和POST方法来请求一个Servlet。文章还提到,对于刚开始学习Web开发的读者,了解这些基本概念是非常重要的。通过这篇文章,读者可以更好地理解Servlet和JSP在网页开发中的作用以及它们如何与HTTP协议配合工作。

 <%@ page language=”java” import=”java.util.*” contentType=”text/html; charset=utf-8″%> <% String path=request.getContextPath(); String basePath=request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”; %> <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”> <html> <head> <base href=”https://www.jb51.net/article/<%=basePath%>” rel=”external nofollow” > <title>My JSP ‘index.jsp’ starting page</title> <meta http-equiv=”pragma” content=”no-cache”> <meta http-equiv=”cache-control” content=”no-cache”> <meta http-equiv=”expires” content=”0″> <meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″> <meta http-equiv=”description” content=”This is my page”> <!– <link rel=”stylesheet” type=”text/css” href=”https://www.jb51.net/article/styles.css” rel=”external nofollow” > –> </head> <body> <h1>第一个Servlet小例子</h1> <a href=”https://www.jb51.net/article/servlet/HelloServlet” rel=”external nofollow” >Get方式请求HelloServlet</a> <form action=”servlet/HelloServlet” method=”post”> <input type=”submit” value=”Post方式请求HelloServlet”> </form> </body> </html>