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

随心笔谈2年前发布 admin
189 0 0

文章摘要

这篇文章介绍了如何使用JavaServer Pages(JSP)创建一个简单的Servlet应用程序。文章从HTML的设置开始,展示了如何通过`<base>`标签设置超链接,并使用`<title>`标签设置页面标题。在`<meta>`标签中,文章设置了`pragma`、`cache-control`、`expires`以及关键词(`keyword1`、`keyword2`、`keyword3`)和描述。接着,文章通过`<link>`标签引入了CSS样式表。 在`<body>`部分,文章展示了如何使用`<h1>`标签标题,并通过链接和表单(使用`<form>`标签和`<input>`标签)展示了两种请求方式:Get方式和Post方式。文章重点在于展示了如何通过JSP快速构建一个简单的Servlet应用,并通过代码示例说明了不同请求方式的实现方法。


<%@ 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>

© 版权声明

相关文章