首页 > Web开发 > 详细

Jsp动态页面关于IDE默认添加的语句的说明

时间:2016-08-14 13:02:58      阅读:211      评论:0      收藏:0      [点我收藏+]

当新建Web Project后,在WebRoot中IDE自动生成的index.jsp。index.jsp默认生成的代码内容中:

 1 <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
 2 <%
 3 String path = request.getContextPath();
 4 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 5 %>
 6 
 7 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 8 <html>
 9   <head>
10     <base href="<%=basePath%>">
11     
12     <title>My JSP index.jsp starting page</title>
13     <meta http-equiv="pragma" content="no-cache">
14     <meta http-equiv="cache-control" content="no-cache">
15     <meta http-equiv="expires" content="0">    
16     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
17     <meta http-equiv="description" content="This is my page">
18     <!--
19     <link rel="stylesheet" type="text/css" href="styles.css">
20     -->
21   </head>
22   
23   <body>
24     This is my JSP page. <br>
25   </body>
26 </html>

需要解释第3行,第4行和第10行。

第3行为request.getContextPath(),是你的新建时指定的工程名。这个名字是部署到服务器上的名字。

第4行为request.getScheme()得到协议的内容(例如Http),request.getServerName()得到服务器的域名(IP地址也可),request.getServerPort()得到服务器的端口号,而最后的path即为第3行的request.getContextPath(),得到部署在服务器上的工程名。

再看一下第4行的代码,中间的连接字符,举个例子给你做个对比你就知道啥意思了,http://127.0.0.1:8080/kantai/

第10行代码的意思是假如你在index.jsp页面有一个aaa.html超链接,那你点击超链接的时候要访问的地址是http://127.0.0.1:8080/kantai/aaa.html,你明白了吧。

待更新。。。。。。。。。

Jsp动态页面关于IDE默认添加的语句的说明

原文:http://www.cnblogs.com/yzyqqhr/p/5769961.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!