高手,您好:
最近學生我新學Java EE遇到了下面的問題:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String errorMessage=(String)request.getAttribute("errorMessage");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>遠程電子醫療診斷系統-登陸</title>
<link href="https://bbs.csdn.net/topics/images/login.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrap">
<div id="header"><img src="https://bbs.csdn.net/topics/images/1428906892_831341.png" /> </div>
<div id="content-wrap">
<div class="space"> </div>
<form action="<%=basePath %>login.do?method=doLogin" method="post"><div class="content">
<div class="field"><label>賬 戶:</label><input class="username" name="username" type="text" /></div>
<div class="field"><label>密 碼:</label><input class="password" name="password" type="password" /><br /></div>
<div class="field"><label>用戶型別:</label><br/><select name="userType" style="width:140px;height:25px;"><option value="https://bbs.csdn.net/topics/doctor">醫生用戶</option><option value="https://bbs.csdn.net/topics/patient">患者用戶</option> </select><br />
<%
if(errorMessage!=null){ %>
<font color="red"> <%=errorMessage %></font>
<% }
%>
</div>
<div class="btn"><input name="" type="submit" class="login-btn" value="" /></div>
</div></form>
</div>
<div id="footer"> </div>
</div>
</body>
</html>
這段代碼中,學生我看不懂第四行的代碼:
:
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
它的方法:“getScheme()”,“getServerName()”,“getServerPort()”,這三個方法的具體使用方法,到哪里去查?
如果高手您的意思是:“到網路中找Struts2 的API.chm”“的話,小弟我請求高手,能夠推薦小弟一款”中文版“,”Struts2“,”無病毒木馬“,的好用靠譜的Struts2的Chm格式的API。
謝謝高手!!
uj5u.com熱心網友回復:
這個陳述句是用來拼裝當前網頁的相對路徑的。<base href="https://bbs.csdn.net/topics/...">是用來表明當前頁面的相對路徑所使用的根路徑的。
比如,頁面內部有一個連接,完整的路徑應該是 http://localhost:80/myblog/authen/login.do
其中http://server/是服務器的基本路徑,myblog是當前應用程式的名字,那么,我的根路徑應該是那么http://localhost:80/myblog/。
有了這個<base ... >以后,我的頁面內容的連接,我不想寫全路徑,我只要寫 authen/login.do就可以了。服務器會自動把<base ...>指定的路徑和頁面內的相對路徑拼裝起來,組成完整路徑。
如果沒有這個<base...>,那么我頁面的連鏈接就必須寫全路徑,否則服務器會找不到。
request.getSchema()可以回傳當前頁面使用的協議,就是上面例子中的“http”
request.getServerName()可以回傳當前頁面所在的服務器的名字,就是上面例子中的“localhost"
request.getServerPort()可以回傳當前頁面所在的服務器使用的埠,就是80,
request.getContextPath()可以回傳當前頁面所在的應用的名字,就是上面例子中的myblog
這四個拼裝起來,就是當前應用的跟路徑了
uj5u.com熱心網友回復:
http://bbs.csdn.net/topics/190149328上面的答案這個帖子里面有 可以查看一下
uj5u.com熱心網友回復:
Servlet內容,到Servlet API中查找轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/150972.html
標籤:網絡通信
上一篇:如何把此處的注冊表內容恢復
