Hello,guys~
It’s Val,it has been a long time that I haven’t update my blog.
In the last few days,every time when I try to write an essay here,problems comes out…
Account login、changing password、and the worst things is I just finished an essay about Java,I haven’t publish that essay,it turn to unreadable code,that drives me crazy,so..
And you might wonder why I wrote this blog in English,because these days I am watching US TV series,I strongly recommend this TV series “Once upon a time” to you,the Chinese name of the US series is “童話鎮”,it’s the most awesome US TV series I’ve ever seen.
今天除了上面的推薦,我主要分享的是JSP相關的基礎知識。
JSP,全稱Java Server Pages。
1、JSP是運行在服務端的語言(是一種動態網頁開發技術),JSP 技術是以 Java 語言作爲腳本語言的,JSP 網頁爲整個服務器端的 Java 庫單元提供了一個接口來服務於HTTP的應用程序。
2、它使用JSP標籤在HTML網頁中插入Java代碼。標籤通常以<%開頭以%>結束。
3、主要用於實現Java web應用程序的用戶界面部分。網頁開發者們通過結合HTML代碼、XHTML代碼、XML元素以及嵌入JSP操作和命令來編寫JSP。
4、JSP通過網頁表單獲取用戶輸入數據、訪問數據庫及其他數據源,然後動態地創建網頁。
5、JSP標籤有多種功能,比如訪問數據庫、記錄用戶選擇信息、訪問JavaBeans組件等,還可以在不同的網頁中傳遞控制信息和共享信息。
最近開始自學JSP,發現還挺有意思的,我們在瀏覽器上訪問的網頁可以查看網頁源代碼,可以自己編寫JSP來創建網頁,設計網頁界面內容。
走火入魔看美劇的結果是,在學習JSP過程中,連網頁上顯示的東西都寫的是”Once upon a time”中的臺詞。
編譯環境: Windows 10 MyEclipse
web服務器:Tomcat 7.0
寫一個while循環在JSP中,顯示出臺詞。
1、在MyEclipse下new一個項目,新建一個*.jsp文件;
2、文件內容如下:
<%@ page language="java" import="java.util.*" pageEncoding="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>
<title>While page</title>
</head>
<body>
<%
java.util.List<String> list=new java.util.ArrayList<String>();
list.add("Magic always come with a price.");
list.add("You are my true love,My destiny!");
list.add("Everyone deserves a happy ending~");
list.add("He is not my happy ending,my happy ending is be free,he is just a part of it.");
java.util.Iterator it=list.iterator();
while(it.hasNext()){
%> <%=it.next() %> <br>
<%
}
%>
</body>
</html>
瀏覽器訪問得到結果如下:
查看網頁源代碼如下:
這只是一個簡單的網頁,還可以對它進行“優化”,讓網頁變得更漂亮,目前正在學習中。
今天的分享就到這裏啦。
Good day!