亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? jsp 的模板.txt

?? java學習文檔
?? TXT
字號:
作者:jspfuns
日期:2000-8-10 17:27:55
By Scott Ferguson 

引論 
樣板的框架: Hello, World 
Servlet 評論 
展示留言板 
留言板的模式 
作為應用屬性的留言板 
留言板的邏輯 
結論 



引論 

JSP的強大優勢在于把一種應用的商務邏輯和它的介紹分離開來。用 Smalltalk的面向對象的術語來說, JSP鼓勵MVC(model-view-controller)的web應用。JSP的classes 或 beans 是模型, JSP 是這個視圖, 而Servlet是控制器。 

這個例子是一個簡單的留言板。用戶登錄和留言。 It is also available in the Resin demos 

Role Implementation 
Model A GuestBook of Guests. 
View login.jsp for new users
add.jsp for logged-in users. 
Controller GuestJsp, a servlet to manage the state. 


樣板的框架: Hello, World 

GuestJsp的框架把 "Hello, World" 這個字符串傳給login.jsp頁面。這個框架為留言板設立結構。具體細節將在下面補充。 

這個例子被編譯后可以瀏覽到:

http://localhost:8080/servlet/jsp.GuestJsp 

你可以看到這樣的頁面: 

Hello, world 

JSP模板是以Servlet的處理開始然后把處理結果傳給JSP頁進行格式化。 

Forwarding uses a Servlet 2.1 feature of the ServletContext, getRequestDispatcher(). The request dispatcher lets servlets forward and include any subrequests on the server. It's a more flexible replacements for SSI includes. The RequestDispatcher can include the results of any page, servlet, or JSP page in a servlet's page. GuestJsp will use dispatcher.forward() to pass control to the JSP page for formatting. 

GuestJsp.java: Skeleton package jsp.GuestJsp;

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
* GuestJsp is a servlet controlling user
* interaction with the guest book.
*/
public class GuestJsp extends HttpServlet {
/**
* doGet handles GET requests
*/
public void doGet(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
// Save the message in the request for login.jsp
req.setAttribute("message", "Hello, world");

// get the application object
ServletContext app = getServletContext();

// select login.jsp as the template
RequestDispatcher disp;
disp = app.getRequestDispatcher("login.jsp");

// forward the request to the template
disp.forward(req, res);
}
}


The servlet and the jsp page communicate with attributes in the HttpRequest object. The skeleton stores "Hello, World" in the "message" attribute. When login.jsp starts, it will grab the string and print it. 

Since Resin's JavaScript understands extended Bean patterns, it translates the request.getAttribute("message") into the JavaScript equivalent request.attribute.message. 

login.jsp: Skeleton <%@ page language=javascript %>

<head>
<title><%= request.attribute.message %></title>
</head>

<body bgcolor='white'>
<h1><%= request.attribute.message %></h1>
</body>



Servlet Review
For those coming to JSP from an ASP or CGI background, Servlets replace CGI scripts taking advantage of Java's strength in dynamic class loading. A servlet is just a Java class which extends Servlet or HttpServlet and placed in the proper directory. Resin will automatically load the servlet and execute it. 

doc 
index.html 
login.jsp 
add.jsp 
WEB-INF 
classes 
jsp 
GuestJsp.class 
GuestBook.class 
Guest.class 
The url /servlet/classname forwards the request to the Servlet Invoker. The Invoker will dynamically load the Java class classname from doc/WEB-INF/classes and try to execute the Servlet's service method. 

Resin checks the class file periodically to see if the class has changed. If so, it will replace the old servlet with the new servlet. 

Displaying the Guest Book 

The next step, after getting the basic framework running, is to create the model. 

The GuestBook model
The guest book is straightforward so I've just included the API here. It conforms to Bean patterns to simplify the JavaScript. The same API will work for HashMap, file-based, and database implementations. 

JSP files only have access to public methods. So a JSP file cannot create a new GuestBook and it can't add a new guest. That's the responsibility of the GuestJsp servlet. 

jsp.Guest.java API package jsp;

public class Guest {
Guest();
public String getName();
public String getComment();
}


Resin's JavaScript recognizes Bean patterns. So JSP pages using JavaScript can access getName() and getComment() as properties. For example, you can simply use guest.name and guest.comment 

jsp.GuestBook.java API package jsp;

public class GuestBook {
GuestBook();
void addGuest(String name, String comment);
public Iterator iterator();
}


Resin's JavaScript also recognizes the iterator() call, so you can use a JavaScript for ... each to get the guests: 

for (var guest in guestBook) {
...
}



GuestBook as application attribute
To keep the example simple, GuestJsp stores the GuestBook in the application (ServletContext). As an example, storing data in the application is acceptable but for full-fledged applications, it's better just to use the application to cache data stored elsewhere. 

jsp.GuestJsp.java // get the application object
ServletContext app = getServletContext();

GuestBook guestBook;

// The guestBook is stored in the application
synchronized (app) {
guestBook = (GuestBook) app.getAttribute("guest_book");

// If it doesn't exist, create it.
if (guestBook == null) {
guestBook = new GuestBook();
guestBook.addGuest("Harry Potter", "Griffindor rules");
guestBook.addGuest("Draco Malfoy", "Slytherin rules");
app.setAttribute("guest_book", guestBook);
}
}

RequestDispatcher disp;
disp = app.getRequestDispatcher("login.jsp");

// synchronize the Application so the JSP file 
// doesn't need to worry about threading
synchronized (app) {
disp.forward(req, res);
}


The JSP file itself is simple. It grabs the guest book from the application and displays the contents in a table. Normally, application objects need to be synchronized because several clients may simultaneously browse the same page. GuestJsp has taken care of synchronization before the JSP file gets called. 

login.jsp: Display Guest Book <%@ page language=javascript %>

<head>
<title>Hogwarts Guest Book</title>
</head>

<body bgcolor='white'>

<h1>Hogwarts Guest Book</h1>
<table>
<tr><td width='25%'><em>Name</em><td><em>Comment</em>
<%
var guestBook = application.attribute.guest_book

for (var guest in guestBook) {
out.writeln("<tr><td>" + guest.name + "<td>" + guest.comment);
}
%>
</table>

</body>


Hogwarts Guest Book
Name Comment 
Harry Potter Griffindor Rules 
Draco Malfoy Slytherin Rules 



Guest book logic 

The guest book logic is simple. If the user has not logged in, she sees comments and a form to log in. After login, she'll see the comments and a form to add a comment. login.jsp formats the login page and add.jsp formats the add comment page. 

GuestJsp stores login information in the session variable. 

Form Variable Meaning 
action 'login' to login or 'add' to add a comment 
name user name 
password user password 
comment comment for the guest book 

Guest book logic ...

// name from the session
String sessionName = session.getValue("name");

// action from the forms
String action = request.getParameter("action");

// name from the login.jsp form
String userName = request.getParameter("name");

// password from the login.jsp form
String password = request.getParameter("password");

// comment from the add.jsp form
String comment = request.getParameter("comment");

// login stores the user in the session
if (action != null && action.equals("login") &&
userName != null &&
password != null && password.equals("quidditch")) {
session.putValue("name", userName);
}

// adds a new guest
if (action != null && action.equals("add") &&
sessionName != null &&
comment != null) {
guestBook.addGuest(sessionName, comment);
}

String template;
// if not logged in, use login.jsp
if (session.getValue("name") == null)
template = "login.jsp";
// if logged in, use add.jsp
else
template = "add.jsp";

RequestDispatcher disp;
disp = app.getRequestDispatcher(template);

...


login.jsp and add.jsp just append different forms to the display code in the previous section. 

login.jsp <%@ page language=javascript %>
<head>
<title>Hogwarts Guest Book: Login</title>
</head>
<body bgcolor='white'>

<h1>Hogwarts Guest Book</h1>
<table>
<tr><td width='25%'><em>Name</em><td><em>Comment</em>
<%
var guestBook = application.attribute.guest_book

for (var guest in guestBook) {
out.writeln("<tr><td>" + guest.name + "<td>" + guest.comment);
}
%>
</table>
<hr>

<form action='GuestJsp' method='post'>
<input type=hidden name='action' value='login'>
<table>
<tr><td>Name:<td><input name='Name'>
<tr><td>Password:<td><input name='Password' type='password'>
<tr><td><input type=submit value='Login'>
</table>
</form>
</body>



Conclusion 

The Resin demo shows a few ways to extend the guest book, including adding some intelligence to the form processing. However, as forms get more intelligent, even JSP templates become complicated. There is a solution: XTP templates. 


--------------------------------------------------------------------------------

Home | Resin | Download | Sales | FAQ | Site Map 
Copyright ? 1998-2000 Caucho Technology. All rights reserved. 

Last modified: Sat, 11 Mar 2000 20:22:52 -0800 (PST) 

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色综合婷婷久久| 5566中文字幕一区二区电影| 日韩一区精品字幕| 国产精品久久久久一区| 欧美一级专区免费大片| 色婷婷综合久久久久中文| 国产乱人伦精品一区二区在线观看 | 中文字幕色av一区二区三区| 日韩欧美成人午夜| 欧美在线一区二区三区| 北岛玲一区二区三区四区| 国产一区二区三区黄视频| 亚洲va国产va欧美va观看| 亚洲欧美偷拍卡通变态| 久久久久亚洲蜜桃| 日韩欧美一区电影| 欧美美女一区二区| 欧美系列日韩一区| av不卡在线观看| 国产91精品欧美| 国模大尺度一区二区三区| 日本vs亚洲vs韩国一区三区| 一区二区三区久久久| 一区在线观看免费| 欧美激情综合五月色丁香小说| 日韩欧美久久久| 欧美一区二区三区电影| 666欧美在线视频| 91麻豆精品国产91久久久使用方法| 91麻豆蜜桃一区二区三区| 99久久国产综合精品女不卡| www.成人网.com| va亚洲va日韩不卡在线观看| www.在线成人| 91色九色蝌蚪| 91黄色免费网站| 欧美视频精品在线观看| 欧美日韩亚洲综合在线 | 国产乱码精品一区二区三区av| 蜜臀久久久久久久| 欧美午夜精品一区二区三区| 91免费观看国产| 色吧成人激情小说| 在线影院国内精品| 欧美性猛片aaaaaaa做受| 欧美三级中文字幕| 欧美一区二区三区视频在线| 91精品国产乱| 2022国产精品视频| 久久久99免费| 国产欧美精品区一区二区三区 | 亚洲乱码一区二区三区在线观看| 亚洲欧洲三级电影| 亚洲精品国产精品乱码不99 | 国产精品主播直播| 风间由美性色一区二区三区| 不卡在线观看av| 一道本成人在线| 欧美日韩精品欧美日韩精品一 | 精品视频色一区| 日韩精品一区二区三区在线观看| 久久先锋影音av鲁色资源网| 国产精品久久久久四虎| 亚洲精品一二三四区| 午夜电影网亚洲视频| 九九热在线视频观看这里只有精品| 国产一级精品在线| 色综合久久久久久久久| 欧美日韩在线免费视频| 欧美va亚洲va| 国产精品传媒入口麻豆| 午夜精品一区二区三区电影天堂| 另类小说图片综合网| av在线这里只有精品| 欧美日本在线看| 国产女人18水真多18精品一级做| 一区二区三区成人| 国产综合久久久久久鬼色| 99麻豆久久久国产精品免费优播| 欧美日韩国产综合一区二区| 久久这里只精品最新地址| 亚洲欧美日韩电影| 久久精品国产免费看久久精品| 成人99免费视频| 日韩一二在线观看| 自拍偷自拍亚洲精品播放| 全部av―极品视觉盛宴亚洲| 成人h动漫精品一区二区| 制服丝袜av成人在线看| 国产亚洲综合在线| 日韩精品一区在线| 亚洲精品久久7777| 激情综合网激情| 在线观看网站黄不卡| 国产亚洲一二三区| 日本不卡一二三| 91视视频在线观看入口直接观看www | 久久色.com| 亚洲午夜免费福利视频| 高清不卡一区二区| 日韩一区二区三| 亚洲精品免费在线观看| 国产suv精品一区二区6| 日韩一区二区精品葵司在线| 一个色综合网站| 成人av免费在线观看| 成人精品在线视频观看| 国产性天天综合网| 亚洲福利一区二区| 粉嫩av一区二区三区| 8x8x8国产精品| 一区二区三区在线视频免费 | 91农村精品一区二区在线| 日韩三级视频在线看| 亚洲一二三专区| 99久精品国产| 国产精品嫩草影院com| 韩国视频一区二区| 欧美一区二区三区视频在线观看| 亚洲高清在线精品| 色综合久久久久综合体桃花网| 国产精品色眯眯| 国产精品一区二区免费不卡 | 色综合久久中文综合久久97| 日本一区二区视频在线| 国产成人亚洲精品青草天美| 精品久久久久久久久久久院品网| 青椒成人免费视频| 欧美一卡2卡三卡4卡5免费| 午夜精品久久久久久| 欧美日韩一区精品| 亚洲福利视频导航| 欧美日韩国产经典色站一区二区三区 | 欧美日韩色一区| 婷婷中文字幕综合| 8x8x8国产精品| 蜜桃久久av一区| 精品国产精品网麻豆系列| 国内欧美视频一区二区| 精品国偷自产国产一区| 国产一区 二区| 亚洲国产精品黑人久久久| 波多野结衣精品在线| 亚洲黄色片在线观看| 欧美午夜电影一区| 日韩精品三区四区| 精品福利av导航| 国产成人av电影免费在线观看| 2024国产精品| 99久免费精品视频在线观看 | 一区二区三区四区在线播放| 欧美少妇bbb| 免费的成人av| 久久久久久9999| 99久久99久久精品免费看蜜桃 | 国产福利不卡视频| 国产精品久久一级| 欧美伊人久久久久久久久影院| 亚洲一级电影视频| 精品女同一区二区| 国产99久久久国产精品| 亚洲精品视频自拍| 欧美男人的天堂一二区| 国产在线播放一区三区四| 国产精品理论在线观看| 欧美精品在欧美一区二区少妇| 捆绑调教一区二区三区| 国产精品欧美极品| 欧美色综合久久| 国产九色精品成人porny | 久久久久久久综合日本| 日本韩国欧美三级| 久久精品国产免费看久久精品| 亚洲欧美一区二区在线观看| 91精品国产乱码| jlzzjlzz国产精品久久| 日本视频免费一区| 国产精品国产馆在线真实露脸| 91精品国产一区二区| www.在线成人| 久久99久久99小草精品免视看| 亚洲日本护士毛茸茸| 26uuu色噜噜精品一区二区| 色噜噜久久综合| 九色|91porny| 亚洲成人av一区二区三区| 日本一区免费视频| 91麻豆精品国产91| www.久久久久久久久| 狠狠色丁香久久婷婷综合丁香| 一区二区三区免费网站| 久久这里都是精品| 欧美一区二区三区性视频| 99re热这里只有精品视频| 久久成人免费网| 亚洲超碰97人人做人人爱| 自拍偷自拍亚洲精品播放| 久久久精品免费免费| 欧美一级精品在线| 欧美日韩中文字幕精品|