📄 55.html
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="description" content="Java,JDBC,EJB,Open Source,jdk,rmi">
<meta name="Keywords"
content="Java, servlets, Java servlet, Javascript, ActiveX, VRML,
applet, applets, directory, news, jdbc, applications,
Java applications, Java developer, Java development, developer,
classes, Jars.com, Jars, intranet, Java applet, Javabeans,
Java products, JDK, Java development kit, java development environment, JIT,
JavaPlan, enterprise tools, JVM, Java Virtual Machine, Java resources,
SUN, CGI, Perl, database, network, html,
xml, dhtml, rating, ratings, review, jars, cgi, programming,
software review, software rating">
<title>csdn_Servlet chaining</title>
<style>
.news { BACKGROUND: #007cd3; font-family: "宋体"; font-size: 9pt }
.t { font-family: "宋体"; font-size: 9pt }
.t1 { color:#007cd3; font-family: "宋体"; font-size: 9pt }
.white { font-family: "宋体"; font-size: 9pt;color:#FFFFFF }
.red { font-family: "宋体"; font-size: 9pt;color:#FF0000 }
A:visited {color:#0000FF}
A:hover {color: #ff6666; text-decoration: none}
.text {font-size: 12px; line-height: 160%; font-family: "宋体"}
.text1 {color:#000000; font-size: 12px; line-height: 130%; font-family: "宋体"; text-decoration: none}
.text1:visited {color:#000000}
.text1:hover {color: #000000}
.text2 {color:#000000; font-size: 12px; line-height: 130%; font-family: "宋体"; text-decoration: none}
.text2:visited {color:#000000}
.text2:hover {color: #000000}
.text3 {font-size: 12px; line-height: 100%; font-family: "宋体"; text-decoration: none}
.large {font-size: 14.8px; line-height: 130%}
</style>
</head>
<body
<center>
<tr>
<td WIDTH="100%" VALIGN="TOP">
<tr>
<td WIDTH="100%" CLASS="white"></td>
</tr>
<tr>
<td WIDTH="50%" bordercolor="#FFFFFF" CLASS="t1" bgcolor="#F0F0F0" align="center" nowrap>Servlet chaining</td>
<p></p>
</tr>
<tr> <td WIDTH="100%" bordercolor="#FFFFFF" CLASS="t" bgcolor="#F0F0F0" colspan="2">
<BR><FONT color=#000080>在servlet
chaining
情况下,多个servlet由一个客户HTTP请求调用,每个servlet完成输出HTML的一部分,每个servlet都受到原始的HTTP请求作为输入,并且每个servlet独立的产生它自己的servlet.,与Filtering不同的是,在这种情况下,每个servlet的输入和输出显得更独立了一些。</FONT></FONT><BR><IMG
border=0 height=158 src="s04.jpg" tppabs="http://www.chinajavaworld.com/doc/servlet-jsp/images/s04.jpg"
width=357><BR><FONT color=#000080 size=2>
WebSphere 产品提供了一个 ChainerServlet(in
com.ibm.websphere.servlet.filter),通过一个servlet别名调用它,指定一个原始的请求和多个目标servlet作为初始参数:</FONT>
<P></P>
<P align=left
style="LINE-HEIGHT: 150%; MARGIN-BOTTOM: 5px; MARGIN-TOP: 5px"><FONT
color=#000080 size=2>Parameter name:
chainer.pathlist<BR>Parameter value: /chainFirst
/chainSecond<BR><BR>
每个servlet在这个别名里都被调用,输出的HTML由所有的servlet输出组成。<BR><BR>
下面的代码显示了如何调用两个servlet并且输出一个response,注意,第二个servlet必需延续第一个servlet的输出。如第一个servlet输出一个XML数据段,由第二个servlet为它加上适当的格式或表格,并返回客户端浏览器。<BR></FONT><BR><FONT
color=#000080 size=2>import java.io.*;<BR>import
javax.servlet.*;<BR>import javax.servlet.http.*;<BR>public
class <B>ChainerFirs t</B> extends HttpServlet
{<BR> protected void service(HttpServletRequest req,
HttpServletResponse res)<BR> throws ServletException,
IOException { <BR> res.setContentT
pe("text/html");<BR> PrintWriter out =
res.getWriter();<BR> out.println("<HTML><TITLE>ChainerFirst</TITLE><BODY>");<BR> out.println("<H2>Servlet
API Example -
ChainerFirst</H2><HR>");<BR> out.println("<H4><font
color=\"Red\">This part of the output produced b<BR> the
first servlet..</font></H4>");<BR>}<BR></FONT></P>
<P
style="LINE-HEIGHT: 150%; MARGIN-BOTTOM: 5px; MARGIN-TOP: 5px"><FONT
color=#000080 size=2>import java.io.*;<BR>import
javax.servlet.*;<BR>import javax.servlet.http.*;</FONT></P>
<P
style="LINE-HEIGHT: 150%; MARGIN-BOTTOM: 5px; MARGIN-TOP: 5px"><FONT
color=#000080 size=2>public class <B>ChainerSecond</B> extends
HttpServlet {<BR>protected void service(HttpServletRequest
req, HttpServletResponse res)<BR> throws ServletException,
IOException {<BR> res.setContentT pe(req.getContentT
pe());<BR> PrintWriter out = res.getWriter();<BR> //Need
this to read through the output of the last
servlet:<BR> BufferedReader in = req.getReader();<BR> String
line;<BR> while((line = in.readLine()) !=
null)<BR> out.println(line);<BR> out.println("<H4><font
color=\"Green\">This part of the output
produced<BR> by the second
servlet..</H4>");<BR>
out.println("</BODY></HTML>");<BR>
out.close();<BR>}</FONT></FONT></P>
</td>
</tr>
</td>
</tr>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -