⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 112.html

📁 关于jsp的一些好文章 主要介绍一些关于JSP的应用技巧方面的东西
💻 HTML
字号:

<STYLE type=text/css>
<!--
body,td { font-size:9pt;}
hr { color: #000000; height: 1px}
-->
</STYLE>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD><TITLE>FAQ汇萃 >> Servlet >> 有关servlet和servlet之间通信的问题</title>
</head>
<body >

<p><IMG SRC="../image/jsp001_middle_logo.gif" WIDTH="180" HEIGHT="60" BORDER=0 ALT=""></p>

<table width=100% bgcolor="#cccccc" align=center cellpadding="2" cellspacing="0" border=1 bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr bgcolor="#EFF8FF"><td>
<a href=http://www.jsp001.com/list_thread.php?int_attribute=1>FAQ汇萃</a>
>> <a href=http://www.jsp001.com/list_thread.php?forumid=9&int_attribute=1>Servlet</a>
>> 有关servlet和servlet之间通信的问题 [<a href=http://www.jsp001.com/forum/showthread.php?goto=newpost&threadid=112>查看别人的评论</a>]<br>

<hr><p>由 webmaster 发布于: 2001-01-21 11:13</p><p> </p><p>以下是几种常调用的方法<br>   Servlet to Servlet Communication<br>  <br>   Listing 1: ServletBase<br>   public class ServletBase extends HttpServlet{<br>   static Connection databaseConnection = null;<br>   public void init(ServletConfig _config) throws ServletException{<br>   super.init(_config);<br>   if ( databaseConnection == null )<br>   //- Open up the database connection<br>   }<br>   protected boolean isLoggedOn( String _username ){<br>   return true;<br>   }<br>   protected boolean logUserOn( String _username ){<br>   return true;<br>   }<br>   }<br>   Listing 2: Using the NewSerletBase Class<br>   public class logonServlet extends ServletBase{<br>   public void service(HttpServletRequest _req, HttpServletRe-<br>   sponse _res) throws ServletException{<br>   if ( isLoggedOn( _req.getParameter(襏SERNAME? ){<br>   //- Display a message indicating they are already logged on<br>   }else{<br>   logUserOn( _req.getParameter(襏SERNAME? );<br>   }<br>   }<br>   }<br>   Listing 3: Storing an Object<br>   public class logonServlet extends HttpServlet{<br>   public void service(HttpServletRequest _req, HttpServletRe-<br>   sponse _res) throws ServletException{<br>   ServletContext thisContext = getServletContext();<br>   //-- Assume some method creates a new connection class<br>   Connection newConnection = createConnection();<br>   thisContext.setAttribute( database.connection? newConnection );<br>   //-- Return some output to the client<br>   }<br>   }<br>   Listing 4: retrieving an Object<br>   public class logoffServlet extends HttpServlet{<br>   public void service(HttpServletRequest _req, HttpServletRe-<br>   sponse _res) throws ServletException{<br>   ServletContext thisContext = getServletContext();<br>   //-- Assume some method creates a new connection class<br>   Connection newConnection = thisContext.getAttribute(<br>   database.connection?;<br>   if ( newConnection == null )<br>   //- Database has not been opened yet<br>   //-- Return some output to the client<br>   }<br>   }<br>   Listing 5: Looking at All the Objects<br>   public class allServlet extends HttpServlet{<br>   public void service(HttpServletRequest _req, HttpServletRe-<br>   sponse _res) throws ServletException{<br>   ServletContext thisContext = getServletContext();<br>   //-- Assume some method creates a new Connection class<br>   Enumeration E = thisContext.getAttributeNames();<br>   while ( E.hasMoreElements() ){<br>   String name = (String)E.nextElement();<br>   System.out.println( "Object: " + name );<br>   }<br>   }<br>   }<br>   Listing 6: Retrieving Remote Contexts<br>   public class otherServlet extends HttpServlet{<br>   public void service(HttpServletRequest _req, HttpServletRe-<br>   sponse _res) throws ServletException{<br>   ServletContext otherContext =<br>   getServletContext(http://&lt;otherdomain&gt;/servlet/allServlet?;<br>   //-- Assume some method creates a new Connection class<br>   Enumeration E = otherContext.getAttributeNames();<br>   while ( E.hasMoreElements() ){<br>   String name = (String)E.nextElement();<br>   System.out.println( "Object: " + name );<br>   }<br>   }<br>   }<br>   Listing 7: Forwarding a Request<br>   public class forwardServlet extends HttpServlet{<br>   public void service(HttpServletRequest _req, HttpServletRe-<br>   sponse _res) throws ServletException{<br>   ServletContext xt = getServletContext();<br>   RequestDispatcher xyzServlet =<br>   xt.getRequestDispatcher(http://&lt;domain&gt;/servlet/xyzServlet?;<br>   //- Do any preliminary processing<br>   _req.setAttribute( database.results? new Results() );<br>   xyzServlet.forward( _req, _res );<br>   }<br>   }<br>   Listing 8: Inserting Content<br>   public class insertServlet extends HttpServlet{<br>   public void service(HttpServletRequest _req, HttpServletRe-<br>   sponse _res) throws ServletException{<br>   ServletContext xt = getServletContext();<br>   RequestDispatcher xyzServlet =<br>   xt.getRequestDispatcher(http://&lt;domain&gt;/servlet/xyzServlet?;<br>   PrintWriter Out = _res.getWriter();<br>   Out.println( this is from the insertServlet ?);<br>   for(int x=0; x &lt; 10; x++ )<br>   xyzServlet.insert( _req, _res );<br>   Out.println( this is the end of the print servlet ?);<br>   }<br>   }<br><br></p></td>
  </tr>
</table>

<p>
<CENTER><a href="http://www.jsp001.com/forum/newreply.php?action=newreply&threadid=112">点这里对该文章发表评论</a></CENTER>
<p>该文章总得分是 <font color=red>0</font> 分,你认为它对你有帮助吗?
				[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=112&intVote=4","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>非常多</a>](<font color=red>0</font>) 
				[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=112&intVote=2","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>有一些</a>](<font color=red>0</font>) 
				[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=112&intVote=1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>无帮助</a>](<font color=red>0</font>) 
				[<a href=javascript:void(0) onclick=window.open("http://www.jsp001.com/forum/codeVote.php?threadid=112&intVote=-1","","menubar=no,toolbar=no,location=no,directories=no,status=no,resizable=no,scrollbars=no,width=70,height=40,top=0,left=0")>是灌水</a>](<font color=red>0</font>) </p>
<script language="javascript" src="http://www.jsp001.com/include/read_thread_script.php?threadid=112"></script>
<p><CENTER>
Copyright &copy; 2001 - 2009 JSP001.com . All Rights Reserved <P>

<IMG SRC="../image/jsp001_small_logo.gif" WIDTH="85" HEIGHT="30" BORDER=0 ALT="">
</CENTER></p>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -