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

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

?? 0057.htm

?? JspServlet教程專欄 對javaservlet講述的非常詳細
?? HTM
字號:
<html>

<head>
<title>新時代軟件教程:操作系統 主頁制作 服務器 設計軟件 網絡技術 編程語言 文字編輯</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋體}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1  {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
    <p align="center"><big><strong>JSP - FAQ (2)</strong></big></p>

<div align="right">摘自互聯網</div>

<p>
10) How do you invoke a JSP page from a servlet? TOC <br>
<br>
<br>
<br>
(Contributed by: Thomas-Bernhard.O-Hare@Dresdner-Bank.com)<br>
<br>
After scanning through archives of the JSP mailing list to no effect I finally remembered that I'd pasted this example into a document I wrote. It was originally sent by Satish Dharmaraj of Sun to show the model 2 approach (as described in the 0.92 specification): how to pass data from a servlet<br>
to a JSP.<br>
<br>
Create a directory called model1/ under the samples/ directory. Place foo.jsp and Foo.java inside this directory.<br>
<br>
Compile FooServlet.java and place FooServlet.class in TOP/servlets/directory.<br>
<br>
Then invoke using http://host:8080/servlet/FooServlet<br>
<br>
In this example, FooServlet creates a list and then stores the result in Foo.class. Foo.Class is then passed as a datasource to foo.jsp.<br>
<br>
The sources are:<br>
<br>
1) FooServlet.java<br>
<br>
import java.io.*;<br>
import javax.servlet.*;<br>
import javax.servlet.http.*;<br>
import model1.Foo;<br>
<br>
public class FooServlet extends HttpServlet<br>
{<br>
public void service(HttpServletRequest req, HttpServletResponse res)<br>
throws ServletException, IOException<br>
{<br>
String s[] = new String[] {&quot;blue&quot;, &quot;green&quot;, &quot;red&quot;};<br>
Foo f = new Foo(s);<br>
req.setAttribute(&quot;foo&quot;, f);<br>
<br>
getServletContext().getRequestDispatcher(&quot;/samples/model1/foo.jsp&quot;).forward<br>
(req, res);<br>
}<br>
}<br>
2) foo.jsp<br>
<br>
&lt;html&gt;<br>
&lt;usebean name=foo type=model1.Foo lifespan=page&gt;<br>
&lt;/usebean&gt;<br>
&lt;ul&gt;<br>
&lt;loop property=foo:list propertyelement=x&gt;<br>
&lt;li&gt; &lt;display property=x&gt;<br>
&lt;/loop&gt;<br>
&lt;/ul&gt;<br>
&lt;/html&gt;<br>
3) Foo.java<br>
<br>
package model1;<br>
<br>
public class Foo {<br>
String s[];<br>
public String[] getList() { return s; }<br>
public Foo(String s[]) { this.s = s; }<br>
}<br>
(from &quot;O碒are, Thomas Bernhard&quot; &lt;Thomas-Bernhard.O-Hare@Dresdner-Bank.com&gt;)<br>
11) How do you pass data (including beans) to a JSP from a servlet? TOC <br>
<br>
<br>
<br>
There are actually three different ways to do it, depending on how long the reference should last, and which JSP pages (and servlets, for that matter) should be able to see it. In each of the cases, assume that &quot;myBean&quot; is a reference to the bean you want to send, and that &quot;theBean&quot; is the key I'm going to use to store the bean under (from the servlet perspective), and use as the identity of the bean in the JSP page.<br>
<br>
These techniques are portable to any environment compliant with the servlet API 2.1 and JSP 1.0 specifications. In each case, the passing<br>
works from servlet-&gt;JSP, servlet-&gt;servlet, JSP-&gt;JSP, or JSP-&gt;servlet transitions.<br>
<br>
(1) Request Lifetime<br>
<br>
Use this technique to pass beans that are relevant to this particular request to a bean you are calling through a request dispatcher (using either &quot;include&quot; or &quot;forward&quot;). This bean will disappear after processing this request has been completed.<br>
<br>
SERVLET:<br>
request.setAttribute(&quot;theBean&quot;, myBean);<br>
RequestDispatcher rd =<br>
getServletContext().getRequestDispatcher('/thepage.jsp&quot;);<br>
rd.forward(request, response);<br>
JSP PAGE:<br>
&lt;jsp:useBean id=&quot;theBean&quot; scope=&quot;request&quot; class=&quot;.....&quot; /&gt;<br>
(2) Session Lifetime<br>
<br>
Use this technique to pass beans that are relevant to a particular session (such as in individual user login) over a number of requests. This bean will disappear when the session is invalidated or it times out, or when you remove it.<br>
<br>
SERVLET:<br>
HttpSession session = request.getSession(true);<br>
session.putValue(&quot;theBean&quot;, myBean);<br>
/* You can do a request dispatcher here,<br>
or just let the bean be visible on the<br>
next request */<br>
JSP PAGE:<br>
&lt;jsp:useBean id=&quot;theBean&quot; scope=&quot;session&quot; class=&quot;...&quot; /&gt;<br>
(3) Application Lifetime<br>
<br>
Use this technique to pass beans that are relevant to all servlets and JSP pages in a particular app, for all users. For example, I use this to make a JDBC connection pool object available to the various servlets and JSP pages in my apps. This bean will disappear when the servlet engine is shut down, or when you remove it.<br>
<br>
SERVLET:<br>
getServletContext().setAttribute(&quot;theBean&quot;, myBean);<br>
JSP PAGE:<br>
&lt;jsp:useBean id=&quot;theBean&quot; scope=&quot;application&quot; class=&quot;...&quot; /&gt;<br>
Craig McClanahan<br>
<br>
12) How can I pool connections to my database? TOC <br>
<br>
<br>
<br>
Controlling connections to the database is a desirable thing - having to connect to the database for each page is is expensive, and keeping a connection in a session variable is far too expensive in terms of client connections to the database. Thus, people often create pools for connections to the database that the client comes in and gets and then returns when complete (making sure a try/catch is used to ensure the connection is returned!).<br>
<br>
My personal bias indicates that you shouldn't pool connections to your database inside JSP, you should be using a middleware layer and communicating to it (like RMI or CORBA). However, people do write entire applications in JSP and beans that reside in the web server, so how do you do it?<br>
<br>
From: Bradley Wood &lt;Brad@MARKETING.CO.UK&gt;<br>
<br>
probably instantiate this as a singleton in the global.jsa and then call it.<br>
<br>
for more on this and how its called check the downloadable code examples for this book at www.ora.com<br>
<br>
import java.sql.*;<br>
import java.util.*;<br>
<br>
public class ConnectionPool {<br>
private Hashtable connections;<br>
private int increment;<br>
private String dbURL, user, password;<br>
<br>
public ConnectionPool(String dbURL,<br>
String user,<br>
String password,<br>
String driverClassName,<br>
int initialConnections,<br>
int increment)<br>
// int max?<br>
throws SQLException, ClassNotFoundException {<br>
// Load the specified driver class<br>
Class.forName(driverClassName);<br>
this.dbURL = dbURL;<br>
this.user = user;<br>
this.password = password;<br>
this.increment = increment;<br>
connections = new Hashtable();<br>
<br>
// Put our pool of Connections in the Hashtable<br>
// The FALSE value indicates they're unused<br>
for(int i = 0; i &lt; initialConnections; i++) {<br>
connections.put(DriverManager.getConnection(dbURL, user, password),<br>
Boolean.FALSE);<br>
}<br>
}<br>
<br>
public Connection getConnection() throws SQLException {<br>
Connection con = null;<br>
Enumeration cons = connections.keys();<br>
synchronized (connections) {<br>
while(cons.hasMoreElements()) {<br>
con = (Connection)cons.nextElement();<br>
Boolean b = (Boolean)connections.get(con);<br>
if (b == Boolean.FALSE) {<br>
// So we found an unused connection.<br>
// Test its integrity with a quick setAutoCommit(true) call.<br>
// For production use, more testing should be performed,<br>
// such as executing a simple query.<br>
try {<br>
con.setAutoCommit(true);<br>
}<br>
catch(SQLException e) {<br>
// Problem with the connection, replace it.<br>
con = DriverManager.getConnection(dbURL, user, password);<br>
}<br>
<br>
// Update the Hashtable to show this one's taken<br>
connections.put(con, Boolean.TRUE);<br>
// Return the connection<br>
return con;<br>
} // if<br>
} // while<br>
} // synchro<br>
<br>
// If we get here, there were no free connections.<br>
// We've got to make more.<br>
for(int i = 0; i &lt; increment; i++) {<br>
connections.put(DriverManager.getConnection(dbURL, user, password),<br>
Boolean.FALSE);<br>
}<br>
<br>
// Recurse to get one of the new connections.<br>
return getConnection();<br>
}<br>
<br>
public void returnConnection(Connection returned) {<br>
Connection con;<br>
Enumeration cons = connections.keys();<br>
while (cons.hasMoreElements()) {<br>
con = (Connection)cons.nextElement();<br>
if (con == returned) {<br>
connections.put(con, Boolean.FALSE);<br>
break;<br>
}<br>
}<br>
} // returnConnection<br>
<br>
} // class<br>
From: Andre Richards &lt;AndreRic@mweb.co.za&gt;<br>
<br>
A very good example on connection pooling when using Servlets can be found at : <br>
<br>
http://webdevelopersjournal.com/columns/connection_pool.html<br>
<br>
I succesfully used it in JSP 0.91 as follows :<br>
<br>
&lt;script RUNAT=&quot;SERVER&quot;&gt;<br>
DBConnectionManager connMgr = DBConnectionManager.getInstance();<br>
&lt;/script&gt;<br>
<br>
&lt;%<br>
Connection con = connMgr.getConnection(&quot;freetds&quot;); <br>
if (con == null) { <br>
out.println(&quot;Can't get connection&quot;);<br>
return;<br>
}<br>
try {<br>
Statement stmt = con.createStatement();<br>
ResultSet rs = stmt.executeQuery (&quot;SELECT Hello FROM World&quot;);<br>
while(rs.next()) {<br>
out.println(rs.getString(&quot;Hello&quot;));<br>
}<br>
stmt.close();<br>
rs.close();}<br>
catch (SQLException e) {<br>
e.printStackTrace(out)<br>
}<br>
connMgr.freeConnection(&quot;freetds&quot;, con);<br>
%&gt;<br>
13) How do I use other languages in my JSP? TOC <br>
<br>
<br>
<br>
JSP is *Java* Server Pages, and the tags for other languages were taken out in 0.92. That said, two implementations (as of writing) support other languages:<br>
<br>
- PolyJsp, 0.92, http://www.plenix.org/polyjsp, free + open source<br>
- Resin. A JSP 0.92 implementation for compiled JavaScript, http://www.caucho.com/, free for personal use<br>
<br>
14) How can I set a cookie in JSP? TOC <br>
<br>
<br>
<br>
This should work:<br>
<br>
response.setHeader(&quot;Set-Cookie&quot;, &quot;cookie string&quot;);<br>
To give the response-object to a bean, write a method setResponse<br>
(HttpServletResponse response)<br>
- to the bean, and in jsp-file:<br>
<br>
&lt;%<br>
bean.setResponse (response);<br>
%&gt;<br>
(from Aapo Kyr鰈?&lt;aapo.kyrola@SATAMA.COM&gt;)<br>
<br>
15) Can JSP and Servlet share same Session and Beans? TOC <br>
<br>
<br>
<br>
Example: I used Beans and Session with my servlet, JSP can use same Beans and Session or not?<br>
<br>
From: Robert Hodges &lt;hodges@TILDENPARK.COM&gt;<br>
<br>
This can be done, but you are likely to run into problems with class loaders. For instance, we have Apache/JServ which uses the AdaptiveClassLoader along with GNU-JSP which has a different class loader. If you just casually allocate objects in a servlet and then pick them up in JSP pages, you'll most likely get the dreaded ClassCastException, which signals the VM's pleasure when you try to cast a class that was brought in by a different class loader.<br>
<br>
Note that there are sometimes problems even within JSP, as GNU-JSP drops the class loader every time you recompile a page, so if you allocated a class instance using one version of the page, then recompiled and tried to fish that instance back again, you would either (1) not find it or (2) get the ClassCastException (but see para #1 above).<br>
<br>
If you really need to pass information around, the best way for Apache and GNU-JSP is to do the following:<br>
<br>
Have one server per person when developing. <br>
Make sure that all your Java classes, including servlet code, load through the system class path. This means they load through the primordial loader, which does not go away or change. <br>
Make sure that your compiled JSP pages go to another location than your regular Java classes. That way, the JSP loader will just pick them up through the primordial loader. <br>
In this scheme, you will need to reboot the Web server each time you make a change to the regular Java classes or else great confusion will ensue. (And possibly outrage among your users, I might add.)<br>
<br>
If you need to share a Web Server between multiple people, or cannot reboot whenever you make class changes, the solution is much more complex. I can post a treatise on one approach at a later time (big project, deadline Friday) if there is interest.<br>
<br>
16) How do I plug JSP into Microsoft's IIS Web Server? TOC <br>
<br>
<br>
<br>
IBM's WebSphere, LiveSoftware's JRun and New Atlanta's ServletExec all provide plug ins for IIS 4.0.<br>
<br>
Tomcat, the &quot;reference&quot; implementation of JSP 1.1 from the Jakarta Project also has an ISAPI plug-in. Tomcat does not (as of 3.1) support multi-homing.<br>
<br>
Resin also provides support for multi-homing (very well at that!) <br>
<br>
17) Are there any newsgroups that discuss JSP? TOC <br>
<br>
<br>
<br>
Live Software has a new newsgroup for JSP discussion at news://news.livesoftware.com/livesoftware.jsp<br>
<br>
</p>

  </table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品乱码久久久久久日本蜜臀| 成人小视频在线观看| 欧美在线999| 亚洲自拍都市欧美小说| 欧美性受极品xxxx喷水| 丝袜美腿亚洲一区| 日本三级韩国三级欧美三级| 久久精品一区二区三区av| 国产精品久久夜| 三级在线观看一区二区 | 一本到高清视频免费精品| 成人性生交大片| 色拍拍在线精品视频8848| 国产精品美女www爽爽爽| 久久先锋影音av| 欧美电影在线免费观看| 波多野结衣中文一区| 国内精品国产成人国产三级粉色| 亚洲制服丝袜在线| 亚洲欧美一区二区视频| 五月综合激情日本mⅴ| 蜜臀精品一区二区三区在线观看| 色综合网色综合| 日韩午夜电影在线观看| 91精品国产色综合久久不卡电影| 欧美一卡二卡在线| 国产精品免费aⅴ片在线观看| 青草av.久久免费一区| 精品国产91久久久久久久妲己| 激情综合网激情| 久久美女艺术照精彩视频福利播放| 成人精品视频一区| 午夜视频在线观看一区二区三区| 日韩美女一区二区三区| 成人免费看视频| 亚洲伊人色欲综合网| 国产视频在线观看一区二区三区| 色狠狠一区二区| 精品午夜久久福利影院| 亚洲精品久久7777| 久久综合九色综合欧美98 | 精品国产乱子伦一区| 亚洲日本一区二区三区| 欧美一区二区三区男人的天堂| 国产999精品久久| 日韩精品视频网| 亚洲综合一区二区三区| 精品剧情在线观看| 欧美丰满嫩嫩电影| av电影在线不卡| 国产乱码精品1区2区3区| 亚洲一区二区精品久久av| 久久精品一区二区三区四区| 91麻豆精品国产91久久久久| 亚洲一级二级三级在线免费观看| 精品999久久久| 日韩一区二区视频| 欧美挠脚心视频网站| 色综合天天天天做夜夜夜夜做| 国产在线不卡一卡二卡三卡四卡| 日本网站在线观看一区二区三区 | 中文一区一区三区高中清不卡| 欧美在线影院一区二区| av电影一区二区| 国产福利一区在线观看| 九九热在线视频观看这里只有精品| 亚洲大片精品永久免费| 亚洲精品ww久久久久久p站| 国产精品进线69影院| 中文字幕的久久| 中文字幕成人在线观看| 国产日韩欧美综合在线| 国产亚洲综合性久久久影院| 欧美v国产在线一区二区三区| 日韩一级片在线观看| 国产色综合久久| 欧美成人福利视频| 精品欧美久久久| 欧美xxxx老人做受| 久久综合九色欧美综合狠狠| 日韩精品一区在线观看| 久久综合色之久久综合| 国产网红主播福利一区二区| 久久久精品国产免大香伊| 久久嫩草精品久久久精品一| 国产欧美日韩视频在线观看| 中文字幕av一区 二区| 国产精品伦一区| 91视频免费观看| 国内精品自线一区二区三区视频| 国产精品成人免费在线| 国产亚洲欧美激情| 日本高清不卡在线观看| 精品成人私密视频| 色偷偷久久人人79超碰人人澡 | 在线一区二区三区做爰视频网站| 777亚洲妇女| 欧美自拍偷拍一区| 91麻豆精品国产91久久久使用方法 | 精品少妇一区二区三区日产乱码 | 久久精品国产精品亚洲红杏| 91麻豆精品国产自产在线观看一区 | 蜜臀91精品一区二区三区| 日韩美女主播在线视频一区二区三区| 91精品久久久久久久99蜜桃| 久久久三级国产网站| 国产精品久久免费看| 一区二区成人在线视频| 日韩精品免费视频人成| 国产传媒日韩欧美成人| 91麻豆成人久久精品二区三区| 欧美在线影院一区二区| 精品99999| 亚洲精品一区二区在线观看| 国产精品久久久久久久久免费樱桃| 亚洲综合男人的天堂| 美国一区二区三区在线播放| 不卡一区中文字幕| 日韩一级片在线观看| 国产精品美女www爽爽爽| 视频一区在线视频| 国产sm精品调教视频网站| 色老汉av一区二区三区| 欧美最猛性xxxxx直播| 欧美日韩成人激情| 精品国产乱码久久久久久久久| 亚洲另类一区二区| 中文字幕一区二区三区乱码在线| 亚洲综合免费观看高清完整版 | 成人欧美一区二区三区小说| 国产成人精品免费一区二区| 在线精品视频免费播放| 26uuu精品一区二区| 亚洲丝袜自拍清纯另类| 午夜视频一区二区三区| 91久久精品午夜一区二区| 欧美日韩久久一区二区| 亚洲黄色av一区| 亚洲综合在线电影| 国产揄拍国内精品对白| 欧美性视频一区二区三区| 国产精品嫩草久久久久| 国产一区久久久| 日韩一级视频免费观看在线| 亚洲国产一区二区在线播放| 国产激情精品久久久第一区二区 | 久久精品国产一区二区三| 国产片一区二区| 麻豆国产91在线播放| 亚洲午夜av在线| 91原创在线视频| 亚洲精品国产精品乱码不99| 91免费看片在线观看| 天堂资源在线中文精品| 日韩精品一二区| 亚洲人成7777| 中文在线一区二区| 国产乱人伦偷精品视频免下载| 91精品国产综合久久国产大片| 亚洲精品中文在线影院| 99久久免费国产| 国产精品久久久久桃色tv| 国产精品亚洲视频| 精品国产免费久久| 精品一区二区影视| 精品美女在线播放| 狂野欧美性猛交blacked| 日韩视频在线永久播放| 久久成人18免费观看| 日韩免费观看高清完整版| 蜜桃精品在线观看| 亚洲精品一区二区在线观看| 狠狠色综合播放一区二区| 欧美精品一区男女天堂| 国产69精品久久久久毛片| 欧美激情一区二区在线| 波多野结衣精品在线| 中文字幕一区av| 欧美主播一区二区三区| 亚洲高清中文字幕| 日韩女优制服丝袜电影| 国产在线不卡一区| 国产免费观看久久| av亚洲精华国产精华精华| 亚洲综合成人在线视频| 欧美日韩亚洲另类| 麻豆视频观看网址久久| 国产日韩精品一区| 色综合欧美在线视频区| 亚洲影视在线观看| 欧美大片拔萝卜| 成人激情午夜影院| 亚洲一区二区影院| 欧美大片一区二区三区| 成人黄色一级视频| 亚洲综合免费观看高清完整版| 777午夜精品视频在线播放| 老司机午夜精品| 国产精品国产三级国产普通话蜜臀 | 一区二区激情视频|