??xml version="1.0" encoding="utf-8" standalone="yes"?>国产精品一区二区日韩,依依成人精品视频,欧洲亚洲一区二区三区http://www.aygfsteel.com/yuxh/category/42716.htmlwayzh-cnThu, 24 Sep 2015 02:35:48 GMTThu, 24 Sep 2015 02:35:48 GMT60JBoss Forge 2入门教程http://www.aygfsteel.com/yuxh/archive/2015/09/23/427327.htmlyuxhyuxhWed, 23 Sep 2015 13:14:00 GMThttp://www.aygfsteel.com/yuxh/archive/2015/09/23/427327.htmlhttp://www.aygfsteel.com/yuxh/comments/427327.htmlhttp://www.aygfsteel.com/yuxh/archive/2015/09/23/427327.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/427327.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/427327.html阅读全文

yuxh 2015-09-23 21:14 发表评论
]]>
JDBC Recipes(一IntroductionQ?/title><link>http://www.aygfsteel.com/yuxh/archive/2010/04/30/319799.html</link><dc:creator>yuxh</dc:creator><author>yuxh</author><pubDate>Fri, 30 Apr 2010 05:54:00 GMT</pubDate><guid>http://www.aygfsteel.com/yuxh/archive/2010/04/30/319799.html</guid><wfw:comment>http://www.aygfsteel.com/yuxh/comments/319799.html</wfw:comment><comments>http://www.aygfsteel.com/yuxh/archive/2010/04/30/319799.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/yuxh/comments/commentRss/319799.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/yuxh/services/trackbacks/319799.html</trackback:ping><description><![CDATA[<p>What Is JDBC Q?/p> <p>  JDBC 是java~程中一pd允许单连接到很多数据库(特别是关pd数据库)~程APIs . In Java 2 Platform, Standard Edition (J2SE) 5.0,<br>JDBC API ׃个包定义: <p>java.sql Q提供java讉K处理贮存在数据源Q特别是关系型数据库Q中的数据,有最基础常用的对象如Connection, ResultSet, Statement, and PreparedStatement。这个包j2se 和j2eeq_都可使用? <p>javax.sqlQ提供java讉K处理服务器端数据源。这个包lj2ee提供服务Q如DataSource 和RowSet? <p>ODBC bridge是以ODBC标准 C API 方式实现JDBC 的库? <p>而言之,JDBC是一个和database-independent 的访问数据库的API? <p>DriverManager是唯一可以创徏数据库连接的cRDriverManagerҎ各个厂商Q如Oracle, MySQL, and SybaseQ提供的驱动创徏数据库? <p>What Is ODBC Q? <p>  Open Database Connectivity (ODBC) 是一U来自微软的~程接口Q他为Windows应用E序讉K|络上数据库提供了通用语言?ODBC is a C-based interface<br>to SQL-based database systems. It provides a consistent interface for communicating with a database and for accessing database metadata (information about the database system vendor and how the tables, views, and data are stored).ODBC作ؓ标准出现。厂商ؓ各自的DBMS提供了各U的驱动或bridges。从java客户端访问ODBC-based数据库,可以使用JDBC-ODBC bridgeQ因此可以用JDBC-ODBC bridge讉K支持ODBC的数据库Q比如Microsoft Access。微软ؓ他的操作pȝ提供ODBC driver manager。ODBC driver manager协调讉KODBC驱动和对应的数据源? <p>问题Q如果用c++写数据库客户端,你不得不在另一q_重新写客LQPC版的不能在Macintosh上运行。两个原因:1.c++不是跨^台的Q很多东西没有特别指定(如int型用多少位表C)2 更重要的是,想网l访问,GUI框架库等在各个^C同。ODBC的另一个问题是Q接口复杂学习时间长。JDBC去除了这些问题,问关pL据库引入q_无关的解x案。因为性能问题和缺事务支? JDBC-ODBC bridge 驱动只适合实验用或没有其他可选方法? <p>What Is a JDBC-ODBC Bridge? <p>   而言之,JDBC-ODBC bridge通过大多数ODBC驱动来提供JDBC讉K。它是一个把JDBC操作转换为ODBC操作的JDBC驱动。(ODBC操作是由 C-based libraries实现的——ODBC功能仍然在二q制代码库中Q如果数据库或硬件^台更换,需要替换ODBC库)。brige作ؓsun.jdbc.odbc包实玎ͼ包含一个native library用来讉KODBC。sun.jdbc.odbc包在/jre/lib/rt.jar中,包含一个sun.jdbc.odbc.JdbcOdbcDriverc,用来JDBC驱动。注意,JDBC-ODBC bridge是一U“万能”的方式Q因此可能比一些特别设计的JDBC驱动慢? <p>SQL is a Data Manipulation Language (DML—媄响数据库对象内容的命令集) and a Data Definition Language (DDL—媄响数据库对象l构的命令集).SQL also 提供控制事务命o (such as commit and rollback) <p>q接jdbc的过E参?a href="http://www.aygfsteel.com/yuxh/archive/2009/04/24/267280.html" target="_blank">JDBC加蝲分析</a> 。MJDBC驱动的作用是提供各种数据库的具体实现(实现了java.sql.Driver接口)Q隐藏具体数据库的细节(每个数据库厂商可能会为同一个数据库提供不止一个驱动,q些效率Qh?性能会有不同Q? <p>在fianlly中立d?释放 JDBC资源(such as the ResultSet, Statement, PreparedStatement, and Connection objects)Q而不是等他们自己关闭Q会改进应用E序的性能。写一个工L释放q些资源是一个好办法?<p>JDBC API主要用来传SQL statementl数据库Q但也能d表格式数据源的数据,q种来自javax.sql.RowSetl接口的d能力可以被定制去使用更新spreadsheet,flat file cM表格式数据源的数据?<p>JDBC有四U类型的驱动q接数据库?/p> <p>异常QSQLException:有getNextException()可以链接一pd异常Q还有很多方法可以展C额外的错误/异常信息。SQLWarning:SQLException的子c,表示非致命可忽略BatchUpdateException:扚w更新时出现的错误Q除了SQLException提供的信息,q有错误发生前已成功执行多少条数据DataTruncation:意外truancate 数据抛出?/p><img src ="http://www.aygfsteel.com/yuxh/aggbug/319799.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/yuxh/" target="_blank">yuxh</a> 2010-04-30 13:54 <a href="http://www.aygfsteel.com/yuxh/archive/2010/04/30/319799.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>JNDIhttp://www.aygfsteel.com/yuxh/archive/2010/04/29/319685.htmlyuxhyuxhThu, 29 Apr 2010 06:59:00 GMThttp://www.aygfsteel.com/yuxh/archive/2010/04/29/319685.htmlhttp://www.aygfsteel.com/yuxh/comments/319685.htmlhttp://www.aygfsteel.com/yuxh/archive/2010/04/29/319685.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/319685.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/319685.htmlJava Naming and Directory Interface (JNDI) is an API that supports accessing naming and directory services in Java programs.

命名服务目的Q把命名和对象联pv来,提供用命名访问对象的Ҏ?/p>

目录服务Q允许属性和对象联系Q比如用户对象的email地址属性,Q命名服务不提供Q,因此能利用目录服务访问对象属性或以属性ؓ基础查找对象?/p>

yuxh 2010-04-29 14:59 发表评论
]]>
HTTP基础http://www.aygfsteel.com/yuxh/archive/2010/04/02/317324.htmlyuxhyuxhFri, 02 Apr 2010 08:16:00 GMThttp://www.aygfsteel.com/yuxh/archive/2010/04/02/317324.htmlhttp://www.aygfsteel.com/yuxh/comments/317324.htmlhttp://www.aygfsteel.com/yuxh/archive/2010/04/02/317324.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/317324.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/317324.htmlHTTP在TCP/IP的顶层,他是一U有webҎ的|络协议。HTTP会话l构是一U简单的h/响应序列Q浏览器hQ服务器响应 。HTTP 响应可以 包含HTMLQHTTP在响应内容(服务器返回的M东西Q之上添加头信息。浏览器利用头信息来帮助处理html面。把hml内容看作_脓在HTTP响应中的数据。HTTPh中有几个ҎQ最常用的是POST和GET(区别)。HTTP响应中包含状态代码(?04),内容cdQ也UCؓMIMEcdQ他告诉览器将会收C么类型的数据以便处理Q比如展C图片,提供htmlQ,响应的真实内容(htmlQ图片等Q?/p>

yuxh 2010-04-02 16:16 发表评论
]]>
HttpServletRequestWrapper相关http://www.aygfsteel.com/yuxh/archive/2009/11/22/303262.htmlyuxhyuxhSun, 22 Nov 2009 14:30:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/11/22/303262.htmlhttp://www.aygfsteel.com/yuxh/comments/303262.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/11/22/303262.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/303262.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/303262.html应用一Q解?span style="font-family: Times New Roman">tomcat下中文ؕ码问题(先来个简单的Q?nbsp;

?span style="font-family: Times New Roman">tomcat下,我们通常q样来解决中文ؕ码问题:

qo器代码:

  1. package filter;  
  2.   
  3. import java.io.*;  
  4. import javax.servlet.*;  
  5. import javax.servlet.http.*;  
  6. import wrapper.GetHttpServletRequestWrapper;  
  7.   
  8. public class ContentTypeFilter implements Filter {  
  9.   
  10.     private String charset = "UTF-8";  
  11.     private FilterConfig config;  
  12.       
  13.     public void destroy() {  
  14.         System.out.println(config.getFilterName()+"被销?);  
  15.         charset = null;  
  16.         config = null;  
  17.     }  
  18.   
  19.     public void doFilter(ServletRequest request, ServletResponse response,  
  20.             FilterChain chain) throws IOException, ServletException {  
  21.         //讄h响应字符~码  
  22.         request.setCharacterEncoding(charset);  
  23.         response.setCharacterEncoding(charset);  
  24.           
  25.         HttpServletRequest req = (HttpServletRequest)request;  
  26.           
  27.           
  28.         System.out.println("----h?+config.getFilterName()+"qo");  
  29.         //执行下一个过滤器Q如果有的话,否则执行目标servletQ?/span>  
  30.         chain.doFilter(req, response);  
  31.           
  32.         System.out.println("----响应?+config.getFilterName()+"qo");  
  33.   
  34.     }  
  35.   
  36.     public void init(FilterConfig config) throws ServletException {  
  37.             this.config = config;  
  38.             String charset = config.getServletContext().getInitParameter("charset");    
  39.             if( charset != null && charset.trim().length() != 0)  
  40.             {  
  41.                 this.charset = charset;  
  42.             }  
  43.     }  
  44.   
  45. }  

web.xml中过滤器配置
<!--采用的字符~码配置成应用初始化参数而不是过滤器U有的初始化参数是因为在JSP和其他地方也可能需要?->
 <context-param>
   <param-name>charset</param-name>
   <param-value>UTF-8</param-value>
 </context-param>

 <filter>
  <filter-name>ContentTypeFilter</filter-name>
  <filter-class>filter.ContentTypeFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>ContentTypeFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

equest.setCharacterEncoding(charset); 必须写在W一ơ用request.getParameter()之前Q这h能保证参数是按照已经讄的字W编码来获取?br /> response.setCharacterEncoding(charset);必须写在PrintWriter out = request.getWriter()之前Q这h能保证out按照已经讄的字W编码来q行字符输出?/p>

通过qo器,我们可以保证在Servlet或JSP执行之前p|好了请求和响应的字W编码?/p>

但是q样q不能完全解决中文ؕ码问题:

对于posthQ无论是“获取参数环节”q是“输出环节"都是没问题的Q?/p>

对于gethQ?输出环节"没有问题Q但?获取参数环节"依然出现中文qQ所以在输出时直接将q输出了?/p>

 

原因是posth和geth存放参数位置是不同的Q?/p>

post方式参数存放在请求数据包的消息体中?get方式参数存放在请求数据包的请求行的URI字段中,以?开始以param=value&parame2=value2的Ş式附加在URI字段之后。而request.setCharacterEncoding(charset); 只对消息体中的数据v作用Q对于URI字段中的参数不v作用Q我们通常通过下面的代码来完成~码转换Q?/p>

 String paramValue = request.getParameter("paramName");
paramValue = new String(paramValue.trim().getBytes("ISO-8859-1"), charset);

但是每次q行q样的{换实在是很麻烦,有没有统一的解x案呢Q?/p>

解决Ҏ1: 在tomcat_home"conf"server.xml 中的Connector元素中设|URIEncoding属性ؓ合适的字符~码

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               URIEncoding="UTF-8"
     />

q样做的~点是,同一个tomcat下的其他应用也将受到影响。而其每次部v旉需要类修改配置也很ȝ?/p>

解决Ҏ2:自定义请求包装器包装hQ将字符~码转换的工作添加到getParameter()Ҏ?br />

 

package wrapper;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class GetHttpServletRequestWrapper extends HttpServletRequestWrapper {

    
private String charset = "UTF-8";

    
public GetHttpServletRequestWrapper(HttpServletRequest request) {
        
super(request);
    }


    
/**
     * 获得被装饰对象的引用和采用的字符~码
     * 
     * 
@param request
     * 
@param charset
     
*/

    
public GetHttpServletRequestWrapper(HttpServletRequest request,
            String charset) 
{
        
super(request);
        
this.charset = charset;
    }


    
/**
     * 实际上就是调用被包装的请求对象的getParameterҎ获得参数Q然后再q行~码转换
     
*/

    
public String getParameter(String name) {
        String value 
= super.getParameter(name);
        value 
= value == null ? null : convert(value);
        
return value;
    }


    
public String convert(String target) {
        System.out.println(
"~码转换之前Q?/span>" + target);
        
try {
            
return new String(target.trim().getBytes("ISO-8859-1"), charset);
        }
 catch (UnsupportedEncodingException e) {
            
return target;
        }

    }

}


修改qo器的doFilterҎ 代码如下Q?br />

    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) 
throws IOException, ServletException {
        
// 讄h响应字符~码
        request.setCharacterEncoding(charset);
        response.setCharacterEncoding(charset);
        
// 新增加的代码
        HttpServletRequest req = (HttpServletRequest) request;

        
if (req.getMethod().equalsIgnoreCase("get")) {
            req 
= new GetHttpServletRequestWrapper(req, charset);
        }


        System.out.println(
"----h?/span>" + config.getFilterName() + "qo");
        
// 传递给目标servlet或jsp的实际上时包装器对象的引用,而不是原始的HttpServletRequest对象
        chain.doFilter(req, response);

        System.out.println(
"----响应?/span>" + config.getFilterName() + "qo");
    }

 

 

q样一来,在servlet中调用包装器的getParametersҎ来获取参敎ͼ已l完成了字符~码的{换过E,我们׃需要在每次获取参数时来q行字符~码转换了?br /> ȝQ自己写cȝ承HttpServletRequestWrapperQHttpServletRequestWrapper实现了HttpServletRequest接口。看tomcat的源代码可以发现QServletRequest作ؓ一个Component QServletRequestWrapper作ؓ一个比较标准的Decorator Q实现ServletRequest接口q把ServletRequest当作成员变量Q其他承Decorator 的类Q比如本例中的GetHttpServletRequestWrapper Q就可以很好的操控ServletRequest及其子类Q比如本例中的HttpServletRequestQ,HttpServletRequest的很多方法就可以Ҏ我们的需求做改变Q比如设|字W,LI格?/span>
参考:
http://www.javaeye.com/topic/483158
http://fishhappy365.javaeye.com/blog/484185
http://www.javaeye.com/topic/220230

yuxh 2009-11-22 22:30 发表评论
]]>
HTTP GET/POSTh区别http://www.aygfsteel.com/yuxh/archive/2009/11/22/303258.htmlyuxhyuxhSun, 22 Nov 2009 13:12:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/11/22/303258.htmlhttp://www.aygfsteel.com/yuxh/comments/303258.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/11/22/303258.html#Feedback1http://www.aygfsteel.com/yuxh/comments/commentRss/303258.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/303258.html
  • HTTP 定义了与服务器交互的不同ҎQ最基本的方法是 GET ?POST。事实上 GET 适用于多数请求,而保?POST 仅用于更新站炏V根?HTTP 规范QGET 用于信息获取Q而且应该?安全的和 q等的。所?strong>安全?/strong>意味着该操作用于获取信息而非修改信息。换句话_GET h一般不应生副作用?strong>q等?/strong>意味着对同一 URL 的多个请求应该返回同Ll果。完整的定义q不像看h那样严格。从Ҏ上讲Q其目标是当用户打开一个链接时Q她可以信从自w的角度来看没有改变资源。比如,新闻站点的头版不断更新。虽然第二次h会返回不同的一Ҏ闻,该操作仍然被认ؓ是安全的和幂{的Q因为它Lq回当前的新闅R反之亦然。POST h׃那么L了。POST 表示可能改变服务器上的资源的h。仍然以新闻站点ZQ读者对文章的注解应该通过 POST h实现Q因为在注解提交之后站点已经不同了(比方说文章下面出C条注解)Q?
  • 在FORM提交的时候,如果不指定MethodQ则默认为GEThQForm中提交的数据会附加在url之后Q以?分开与url分开。字母数字字W原样发送,但空D{换ؓ“+“P其它W号转换?XX,其中XXW号?6q制表示的ASCIIQ或ISO Latin-1Q倹{GEThh交的数据攄在HTTPh协议头中Q而POST提交的数据则攑֜实体数据中;
  • GET方式提交的数据最多只能有1024字节Q而POST则没有此限制?
  • Web 上最常用的两U?Http h是 Get h?Post h了。我们在?java web 开发时Q也M?servlet 中通过 doGet ?doPost Ҏ来处理请求;更经常地Q我们会?doGet Ҏ的实C调用 doPost Ҏ。尽做了近两年?web 开发,我对诸如 Get h?Post h的基本概念仍不是十分了解。近日阅诅R?javascript 高E序设计》重新整理了一?Get h?Post h的概念,是MW记吧?

    Get 是从服务器上获取数据Q这是最常见的请求类型。每ơ在览器中输入 URL 打开面Ӟ是向服务器发送一?Get h?Get h的参数是用问可加到 URL l尾Q后面跟着用&q接h的名Uͼ值对。比如网址 http://bt.neupioneer.com/viewthread.php?tid=87813 Q其?tid 为参数名Q?87813 为参数的倹{在~程中,使用 Get 最多的地方是链接列表,其中的参数多是从数据库读出的字段拼接而成。在 Ajax 中,我们也经怋?Get Q通过提取出页面的标签|拼成串后构造一?URL ?Get 在用上是有限制的, URL 的最大长度ؓ 2KB Q因此,如果表单中包含textareaq样的大文本D,׃要用Get了。对于表单来_ Get 是把参数数据队列加到提交表单?ACTION 属性所指的 URL 中,值和表单内各个字D一一对应Q通过 URL 可以看到中传递的参数。因此,相比?Post Q它是不安全的?

    Post 的用场合多是在表单提交的地方,因ؓ?Get 相比Q?Post 可以发送更多的数据Q?javascript 高E序设计》中说最多可以发?2GB Q这多少让我不太怿Q网上一些文章说 IIS4 中最大量?80KB Q?IIS5 中ؓ 100KB Q不知道 Tomcat 中的情况如何?Post 是通过 HTTP Post 机制Q将表单内各个字D与其内Ҏ|在 HTML Header 内一起传送到 ACTION 属性所指的 URL 地址??Get 相比Q?Post 的内Ҏ不会?URL 中显现出来的Q这多少是安全一些的?我在做登录这L表单Ӟ只是请求方式设?Post Q得用户名和密码信息不在浏览器中显玎ͼ但不清楚的是Q是否有更好的方法加密密码等信息Q实在不知道如果h不传到服务器的话Q怎么Ҏ知的h加密Q清楚的朋友不妨l个解决ҎQ。在 Ajax 中,如果要和服务器交互,记得加上 request.setRequestHeader(“Content-Type”,”application/x-www-urlencoded”); q一脚本Q尽很?Ajax 教材中都提到了这一炏V另外要说的是,被传递的参数是要l过~码的。在 javascript 中,~码函数?encodeURIComponent(xx) ?nbsp; 
        以上转自 http://blog.csdn.net/yoland/archive/2009/03/19/4005740.aspx
    一个get的发送请求例子:
    GET /select/selectBeerTaste.jsp?color=dark&taste=malty HTTP/1.1
    Host: www.wickedlysmart.com
    User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.4) Gecko/
    20030624 Netscape/7.1
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/
    plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive

    一个post的发送请求例子:
    POST /advisor/selectBeerTaste.do HTTP/1.1
    Host: www.wickedlysmart.com
    User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.4) Gecko/
    20030624 Netscape/7.1
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/
    plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    color=dark&taste=malty (Request headers 后面有一个传参数的body)
    两个例子的红色的部分很好的看Zget和post传参数区?/span>

    yuxh 2009-11-22 21:12 发表评论
    ]]>
    CAShttp://www.aygfsteel.com/yuxh/archive/2009/11/12/302145.htmlyuxhyuxhThu, 12 Nov 2009 12:57:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/11/12/302145.htmlhttp://www.aygfsteel.com/yuxh/comments/302145.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/11/12/302145.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/302145.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/302145.html
    上面是CAS 基础协议?nbsp;

    CAS 介绍

    CAS h以下特点Q?/p>

    • 开源的企业U单点登录解x案?/li>
    • CAS Server 为需要独立部|的 Web 应用?/li>
    • CAS Client 支持非常多的客户?q里指单点登录系l中的各?Web 应用)Q包?Java, .Net, PHP, Perl, Apache, uPortal, Ruby {?/li>

    CAS 原理和协?/a>

    从结构上看,CAS 包含两个部分Q?CAS Server ?CAS Client。CAS Server 需要独立部|Ԍ主要负责对用L认证工作QCAS Client 负责处理对客L受保护资源的讉KhQ需要登录时Q重定向?CAS Server?

    CAS Client 与受保护的客L应用部v在一P?Filter 方式保护受保护的资源。对于访问受保护资源的每?Web hQCAS Client 会分析该h?Http h中是否包?Service TicketQ如果没有,则说明当前用户尚未登录,于是请求重定向到指定好?CAS Server d地址Qƈ传?Service Q也是要访问的目的资源地址Q,以便d成功q后转回该地址。用户在W?3 步中输入认证信息Q如果登录成功,CAS Server 随机产生一个相当长度、唯一、不可伪造的 Service TicketQƈ~存以待来验证Q之后系l自动重定向?Service 所在地址Qƈ为客L览器设|一?Ticket Granted CookieQTGCQ,CAS Client 在拿?Service 和新产生?Ticket q后Q在W?5Q? 步中?CAS Server q行w䆾合适,以确?Service Ticket 的合法性?/p>

    在该协议中,所有与 CAS 的交互均采用 SSL 协议Q确保,ST ?TGC 的安全性。协议工作过E中会有 2 ơ重定向的过E,但是 CAS Client ?CAS Server 之间q行 Ticket 验证的过E对于用h透明的?/p>

    另外QCAS 协议中还提供?Proxy Q代理)模式Q以适应更加高、复杂的应用场景Q具体介l可以参?CAS 官方|站上的相关文档?/p>

    ?Tomcat 上部|一个完整的 CAS Server 主要按照以下几个步骤Q?/p>

    配置 Tomcat 使用 Https 协议

    如果希望 Tomcat 支持 HttpsQ主要的工作是配|?SSL 协议Q其配置q程和配|方法可以参?Tomcat 的相x档。不q在生成证书的过E中Q会有需要用C机名的地方,CAS 不要使用 IP 地址Q而要使用机器名或域名。(目q程中没使用Q?/p>

    部v CAS Server

    CAS Server 是一?Web 应用包,前面下载的 cas-server-3.1.1-release.zip 解开Q把其中? cas-server-webapp-3.1.1.war 拯?tomcat?webapps 目录Qƈ更名? cas.war。由于前面已配置?tomcat ?https 协议Q可以重新启? tomcatQ然后访问:https://localhost:8443/casQ没配置ssh应该是http://localhost:8080/casQ?Q如果能出现正常?CAS d面Q则说明 CAS Server 已经部v成功?/p>

    虽然 CAS Server 已经部v成功Q但q只是一个缺省的实现Q在实际使用的时候,q需要根据实际概况做扩展和定Ӟ最主要的是扩展认证 (Authentication) 接口?CAS Server 的界面?/p> 参?/strong>http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/index.html
    目也采用jdbc验证,文章介绍了三个基?JDBC ?AuthenticationHandlerQ我使用的cas-server 3.3 多了一个AbstractJdbcUsernamePasswordAuthenticationHandler 直接使用?br />



    yuxh 2009-11-12 20:57 发表评论
    ]]>
    Servlet控制׃n(RequestDispatcher)http://www.aygfsteel.com/yuxh/archive/2009/11/05/301316.htmlyuxhyuxhThu, 05 Nov 2009 09:11:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/11/05/301316.htmlhttp://www.aygfsteel.com/yuxh/comments/301316.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/11/05/301316.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/301316.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/301316.htmljavax.servlet.RequestDispatcher接口。servlet调用h对象?tt class="monofont">getRequestDispatcher()的方法获?tt class="monofont">RequestDispatcher实例Q此实例可以dispatch到指定的路径上的lg(如servlet, JSP,静态文件等)Q?br>    public RequestDispatcher ServletRequest.getRequestDispatcher(String path) Q可以是相对路径但不能超q当前的servlet contextQ不q可以用getContextҎ转发到当前context之外的地方,只是没有MҎ转发到另一个服务器上的context。如果\径以?”开始,它被解释为相对于当前context根,如果路径包含查询字符Q参C被包含到接受lg的参数集的开始处。如果servlet容器׃M原因不能q回RequestDispatcher 该方法返回null。在ServletContextcM有同名方?br>public RequestDispatcher ServletContext.getRequestDispatcher(String path)Q不同之处在?tt class="monofont">ServletContext 中的Ҏ(sevlet2.1引入)只接受绝对URLs(?开?Q?tt class="monofont">ServletRequest 中的Ҏ接受l对和相寏V因此没有理׃用ServletContext中的该方法,可以看作只ؓ历史版本兼容(不过servlet2.5仍然有此Ҏ)。除了用路径q可以用名字指定资源来获?tt class="monofont">RequestDispatcherQServletContext中的ҎQ?br>    public RequestDispatcher ServletContext.getNamedDispatcher(String name)Q此Ҏ允许转发到没必要公开发布的资源,servlet或jsp可能通过web应用描述W获得名字。不能获?tt class="monofont">RequestDispatcher仍然q回null?br>    RequestDispatcher有两个方法:forward()and include()?/tt>forward把整个请求交l代理;include把代理的输出加入调用servletQ个人理解ؓ初始的那个servletQ的response中ƈ且调用servlet仍然处于控制状态,卌求{发后Q原先的Servletq可以l输出响应信息,转发到的Servlet对请求做出的响应ƈ入原先Servlet的响应对象中
        forward把请求从一个servlet转发到服务器上的另一个资源,它允怸个servlet对请求做初始处理Q然后另一个资源来产生responseQ不?tt class="monofont">sendRedirect
    Qforward的整个操作都在服务器内部Q对客户是透明的?tt class="monofont">附加查询字符串或使用h?tt class="monofont">setAttribute的方法可以传递信息给代理
    ?br>

    The rules a forwarding servlet must follow are relatively strict:

    • It may set headers and the status code but may not send any response body to the client (that's the job for an include). Consequently, the forward( ) must be called before the response has been committed.

    • If the response already has been committed, the forward( ) call throws an IllegalStateException.

    • If the response has not been committed but there's content within the response buffer, the buffer is automatically cleared as part of the forward.

    • In addition, you can't get creative by substituting new request and response objects. The forward( ) method must be called with the same request and response objects as were passed to the calling servlet's service method, and the forward( ) must be called from within the same handler thread.

    如果servlet A转发到servlet BQB得到的\径信息应该是和直接调用B一LQ从q方面来说B完全控制h。这也是Z么确保response的缓存会在调用之前冲掉,response没有被提交是很重要的事情?br>    用\径{发的问题是:目标lg不但Ҏ务器lg可见Q也必须对客L可见。出于安全考虑Q可能会让一些组件不是公共可见的Q所以用名字代替路径做{发:getNamedDispatcher 不过没有URI路径也就不能加上查询字符Ԍ路径也不能做调整?br>    forward ?tt style="color: rgb(0,0,0)" class="monofont">sendRedirect谁更?/tt>Qrequest dispatch 在服务器端发生,redirect在客L发生?tt class="monofont">forward最好用在一个组件必d理业务逻辑而且和另一个组件分享结果的情况。sendRedirict最好用于客户需要从一重定向于另一c看h用forward比较有诱惑,因ؓforward在服务器内部完成QsendRedirectq需要从客户端倒一遍,所以forward更快。不q的是处理相对URL的时候会引v问题。例Q?br>public class HomePageForward extends HttpServlet {

      public void doGet(HttpServletRequest req, HttpServletResponse res)
                                   throws ServletException, IOException {
        RequestDispatcher dispatcher = req.getRequestDispatcher("/index.html");
        dispatcher.forward(req, res);
      }
    }

    如果index.html中有<img src="../../../images/trans.gif"/>则图片不能读取?tt class="monofont">sendRedirect会告诉客L文g来源于文件根目录Qforward不会。因Z需要调?tt class="monofont">getContext查询Q?tt class="monofont">sendRedirect更容易{发到其他context的资源中?span style="background-color: rgb(255,0,0)">所以徏议是量?tt class="monofont">sendRedirectQ必ȝ情况下才用forward?/tt> 
        RequestDispatcher的includeҎ把资源的内容攑օ当前的respongse中。它实现了一U我们可以称为编E式服务器端 include。不同于forwardQ在调用include后的servlet A仍然控制response而且可能包含 被包含进来内容的前后内容?br> ?Q?br>        doGet(..){
                res.setContentType("text/html");
                PrintWriter out = res.getWriter();

                out.println("<HTML><HEAD><TITLE>Welcome to Nile</TITLE></HEAD>");
                out.println("<BODY>");

                // Show an item in an online catalog
                out.println("Feast your eyes on this beauty:");

                RequestDispatcher dispatcher =
                 req.getRequestDispatcher("/servlet/NileItem?item=0596000405");
                dispatcher.include(req, res);

                out.println("And, since I like you, it's 20% off!");   
                out.println("</BODY></HTML>");
        }

    使用forwardQ通过附加查询字符?tt class="monofont">setAttributeҎQ信息可以传到被调用资源。Using attributes instead of parameters gives you the ability to pass objects instead of simple stringsQ例
        doGet(..){
                res.setContentType("text/html");
        PrintWriter out = res.getWriter();

        out.println("<HTML><HEAD><TITLE>Welcome to Nile</TITLE></HEAD>");
        out.println("<BODY>");

        // Show items in an online catalog
        RequestDispatcher dispatcher =
          req.getRequestDispatcher("/servlet/NileItem");

        out.println("Feast your eyes on this beauty:");
        req.setAttribute("item", Book.getBook("0596000405"));
        dispatcher.include(req, res);

        // Remove the "item" attribute after use
        req.removeAttribute("item");

        out.println("Or how about this one:");
        req.setAttribute("item", Book.getBook("0395282659"));
        dispatcher.include(req, res);

        out.println("And, since I like you, they're all 20% off!");

        out.println("</BODY></HTML>");
        }
    接受servlet
    public class NileItem extends HttpServlet {

      public void doGet(HttpServletRequest req, HttpServletResponse res)
                                   throws ServletException, IOException {

        // We do not set the content type

        PrintWriter out = res.getWriter();

        Book book = (Book) req.getAttribute("item");

        out.println("<BR>");
        if (book != null) {
          out.println("<I>" + book.getTitle() + "</I>");
          out.println(" by " + book.getAuthor());
        }
        else {
          out.println("<I>No book record found</I>");
        }
        out.println("<BR>");
      }
    }
    通过实例可以很好理解includeQ就是把下一个资源的内容直接攑օ本页面的M地方Q被包含的资源不能改变status code or HTTP headers Q所以NileItem 做Q何改变这些的操作都会被忽略(NileItem 所以没有做q些操作Q。不像forwardQ\径元素和h参数仍然和调用端一栗如果被包含资源要求获得自己的\径元素和h参数Q?it may retrieve them using the following server-assigned request attributes:
    javax.servlet.include.request_uri
    javax.servlet.include.context_path
    javax.servlet.include.servlet_path
    javax.servlet.include.path_info

    The request and response parameters must be the same objects as were passed to the calling servlet's service method, and the include( ) must be called from within the same handler thread.

    The included resource must use an output mechanism that matches the caller's. If the caller uses a PrintWriter, then the included resource must use a PrintWriter. If the caller uses an OutputStream, then the included resource must use an OutputStream. If the mechanisms don't match, the included servlet throws an IllegalStateException. If you can, make sure to use the PrintWriter for all text output, and this won't be a problem.



    yuxh 2009-11-05 17:11 发表评论
    ]]>
    Servlethttp://www.aygfsteel.com/yuxh/archive/2009/05/15/267983.htmlyuxhyuxhFri, 15 May 2009 02:22:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/05/15/267983.htmlhttp://www.aygfsteel.com/yuxh/comments/267983.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/05/15/267983.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/267983.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/267983.htmlservlet没有mainҎQ他受一个叫做容器的java应用Q比如TomcatQ控制。当web server应用Q比如ApacheQ收到容器访问servlethQserver不是先把h直接lservletQ而是先给部vq个servlet的容器,容器“看到”找的是servletQ创Z个对象:HttpServletResponse和HttpServletRequest。容器根据URL扑ֈservletc,个请求创建或从池里分配线E,把request和response对象传给该线E,servlet的生命周期就开始了?br>       容器启动的时候这步就发生了,一启动容器开始找部v的web目。第一L其servletc,W二开始加载这个类。A servlet moves from does not exist to initialized (which really means ready to service client requests), beginning with a constructor. But the constructor makes only an object, not a servlet. To be a servlet, the object needs to be granted servletness. 所以在构造函数和init()之间的状态是一U“半dzȝ态”,q时候不能接触很多作为servlet能接触的资源Qlike getting web app configuration info, or looking up a reference to another part of the applicationQ,所以init()之前都不要做什么操作,不要在构造函C放东ѝ在创徏servlet实例之后在ؓM客户端请求服务之前,容器p用initҎQ你可以在处理请求之前在里面初始化你的servletQ重写此Ҏ可以建立数据库连接,用其他对象注册自qQ。接着调用serviceҎQ重写此Ҏ的可能性不大)Q接着doGet/doPostQ至重写其中一个方法)。servicel束后,U程消亡或者放回池里。但W二个请求来Q容器再ơ创建或从池里分配线E,l箋service->doGet/doPost 序列。因此,在一个时间段内,有多客戯求就有多运行的U程Q当然也受容器的{略、配|或资源限制Q比如指定容器的最大ƈ发线E数Q当h的客h过的时候,客户必ȝ待)?font color="#ff0000">容器q行多个U程来处理多个对一个servlet的请求(不管是不是同一个客户发求,一个请求一个线E)Q对于分布式web应用Q一个JVM只对应一个servlet实例
           成ؓ一个servlet可以l你什么:一个ServletConfig对象Q一个ServletContext?br>        ServletConfig对象Q每个servlet有一个;Use it to pass deploy-time information to the servlet (a database or enterprise bean lookup name, for example)that you don’t want to hard-code into the servlet (servlet init parameters)Q访问ServletContextQParameters are configured in the Deployment DescriptorQ如<init-param>方式配置Q?我们可以通过servletconfig获得初始化参敎ͼgetServletConfig().getInitParameter(“foo?;Q,然后通过setAttribute dispatchl某个jsp面Q但是针对一个servlet的初始化参数很有局限性,所以引入针对应用的<context-param>Q这时候通过servletContext获得初始化参敎ͼgetServletContext().getInitParameter(“foo?Q,q个初始化参数可以被应用的Q意servletQjsp讉K?span style="color: red">注意初始化参数是一个deploy-time constantsQ不能在runtime改变他们Q只能通过重新部v?br>
           ServletContext Q每个web app有一个(严格说来如果是分布式的话Q应该是每个JVM一?/span>Q;Use it to access web app parameters (also confi gured in the Deployment Descriptor) Q类似application bulletin-board功能Q让其他应用也能讉KQ用来获得服务器信息Q比如容器名字和版本Q以及支持的API版本?span style="color: red">ServletContextListener 可以监听ServletContext 的初始化Q从ServletContext中获得初始化参数Q用参数q接数据库,把连接作为attribute存v来以便所有应用都可以讉KQ和销毁阶D(关闭q接Q。ؓ了context attributes U程安全Q可以对contextq行同步锁的方式Q?/p>

    synchronized(getServletContext()) {
         getServletContext().setAttribute(“foo? ?/span>22?;
         getServletContext().setAttribute(“bar? ?/span>42?;
         out.println(getServletContext().getAttribute(“foo?);
         out.println(getServletContext().getAttribute(“bar?);
     }
    

           ServletResponse接口有两U流可供输出QServletOutputStream for bytes, or a PrintWriter for character data.
    例:1   PrintWriter writer = response.getWriter();
               writer.println(“some text and HTML?;
          2   ServletOutputStream out = response.getOutputStream();
               out.write(aByteArray);
            如果不想自己处理Q可通过redirectl一个全新的URLQ注意如果response已提交后不能再redirectQ,或者dispatch the request l你应用中的某个lgQ如jspQ。redirect会先q回l客P客户再重新发hQ而dispatch 的话Q服务器会直接{l某个组件。这样两U方式的区别很明显了?

    servlet->容器调用service()->doGet()/doPost() 产生动态页面ƈ把页面放入response对象Q记住此时容器仍然有引用指向该response对象Q线E完成,容器把response对象转换为HTTP对象Q送回客户端,然后删除request和response对象?

    yuxh 2009-05-15 10:22 发表评论
    ]]>
    JSPhttp://www.aygfsteel.com/yuxh/archive/2009/05/15/269553.htmlyuxhyuxhFri, 15 May 2009 02:21:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/05/15/269553.htmlhttp://www.aygfsteel.com/yuxh/comments/269553.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/05/15/269553.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/269553.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/269553.htmlelements ?span class="docEmphasis">template data?span class="docEmphasis">elements 是jsp的动态部分,他们按照jsp规范作ؓ自定义操作,标签Q以及之间的允许内容Qjsp容器会解?span class="docEmphasis">elements Q当产生response的时?span class="docEmphasis">elements 定义的操作会q行QdynamicQ?span class="docEmphasis">template data是静态文本部分,他们被Q意放在jsp面上直接发送给客户端(not changeQ?br>      elements 又可分ؓ三类Qscripting elements, directives, and actions ?br>scripting elements Q有三种cdQ?br>      1 Scriptlets卛_见到?lt;%.... %>,注意scriptlet 的内容不会发送给客户端,只有scriptlet 的结果会发送,q表明scriptlet 被容器解释,scriptlet 的代码默认情况下不会被访问者分享?代码~译成servlet后在jspService() 内。这里面写的java代码最后结果以out.print(?;输出
         2 Expressions:<%=...=>: 发送字W串l客LQ表辑ּ可以是Q意有toStringҎ的对象,或者是primitive。代码编译成servlet后在jspService() 内?font color="#ff0000">不要在后面加分号Q否则会以out.print(...;); 形式输出Q引L译错?/font>
       3 DeclarationsQ?lt;!=...=>: declaration 像scriptlet一L来向jsp嵌入代码Q这些声明编译成servlet后都是在jspService() Ҏ外面的,所以声明里可用来定义新ҎQ可以被scriptlet调用Q或全局cd量,但声明里代码不是U程安全的,必须自己控制?/tt>

    directives  q不用来向客L输出Q用来定义页面属性,包括定制标签库和包含其他面Q语?Q?br>     <%@ directive {attribute="value"}* %>
    三种不同的jsp directives Q?tt>page
    , taglib, and include?br>  <%@ page %>ljsp容器提供面的相关信?br><%@ include %> is used to include text and/or code at translation time of a JSPQ语?tt><%@ include file="relativeURL" %>,q个文g必须是web 应用的一部分Q由于在转换阶段被包括,相当于在~译之前把文件源代码直接放进来,所以不影响runtime阶段的性能?a class="docLink" href="mk:@MSITStore:E:\Computer%20eBook\j2EE&Web\JSP&Servlet\j2ee技术web层:servlet和jsp\Addison.Wesley.Servlets.and.JavaServer.Pages.The.J2EE.Technology.Web.Tier.eBook-LiB.chm::/0321136497_ch03lev1sec4.html#ch03lev3sec6"><jsp:include /> 在runtime阶段触发Q虽然效能没前面translation time include好,但保证被包括文g的实时性?br><%@ taglib %> 自定义标{ֺQ语?tt><%@ taglib uri="uri" prefix="prefixOfTag" %>
    Actions  可以方便的把动态代码链入简单的jsp面Q功能类似scripting elements Q但是把和jsp打交道的java代码抽象出来了,有两U:standard and custom 语法 <prefix:element {attribute="value"}* />

    jsp中有implicit objectsQ就像在Servlets中的对象Q在scripting elements中可以用:configQrequestQresponseQsessionQ默认jsp持有一个sessionQ在scripting elements 用这个对象,像调用HttpServletRequest getSession() 一PQapplicationQ?tt>javax.servlet.ServletContext
    对象实例Q就像调?tt>ServletConfig getServletContext() 一P q有一些没有直接和Servlet 对应的,但是隐含的对象:pageContextQ含有一个jsp的许多对象资源信息,在定制标{时候用得较多), page, out, and exception

    yuxh 2009-05-15 10:21 发表评论
    ]]>
    Filterhttp://www.aygfsteel.com/yuxh/archive/2009/05/15/269022.htmlyuxhyuxhFri, 15 May 2009 02:21:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/05/15/269022.htmlhttp://www.aygfsteel.com/yuxh/comments/269022.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/05/15/269022.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/269022.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/269022.htmljavax.servlet.Filter接口定义了接口的生命周期Q该接口定义了三个方法:
    1 init(FilterConfig config) Q容器加载filter的时候触发此ҎQ可以用来从web.xml文g攉初始化参C及做些初始化操作?tt>FilterConfig可用来获得初始化数据Q此Ҏ被调用一ơ且仅一ơ?br />
    2 destroy()Q当Filter被从内存中unload的时候调用(最典型的是关闭应用的时候)Q该Ҏ最好用来关闭Filter初始化的外部资源?br /> 3 doFilter(ServletRequest request, ServletResponse response, FilterChain chain) Q执行filter要完成的事情QHttpServlet情况下, ServletRequest?tt>ServletResponse 对象是HttpServletRequest 和HttpServletResponse的实例。Filter 需要类型{换他们以便用HttpServletRequest 和HttpServletResponse对象的方法?br /> FilterConfig 对象用来配置filterQ?tt>FilterChain 对象用来表示filters链中当前应用到request和response中的filter。Filter 和Servlet的功能基本类|唯一区别时候他强制分开链中的各个资源。可以说Filter是有额外功能的Servlet?tt>FilterChain对象可以形象的理解ؓ一UStackQstatck中的某个filter正在某个request和response上运行?tt>FilterConfig ?/span>ServletConfig 极ؓcM
       默认情况filters铑֏能用来处理客L发送的requestQ如果用RequestDispatcher 对象?tt>forward() 或?tt>include() Ҏ发送请求,filter是不能处理的Q但是可通过配置web.xml处理Q?tt>dispatcher元素中有REQUEST, INCLUDE, FORWARD, ERROR四种值可用来配置?br />
    ?Wrapper
         定制request或者response对象的时候,只需要简单的l承request或response的相应wrapperc(是对request或responseq行扩展实现Q。sun公司提供四个方便的wrapperc:

    ServletRequestWrapper
    HttpServletRequestWrapper
    ServletResponseWrapper
    HttpServletResponseWrapper
    wrappercd际上使用了Decorator模式

    yuxh 2009-05-15 10:21 发表评论
    ]]>
    struts2 in actionW记(一)http://www.aygfsteel.com/yuxh/archive/2009/02/22/256098.htmlyuxhyuxhSun, 22 Feb 2009 14:53:00 GMThttp://www.aygfsteel.com/yuxh/archive/2009/02/22/256098.htmlhttp://www.aygfsteel.com/yuxh/comments/256098.htmlhttp://www.aygfsteel.com/yuxh/archive/2009/02/22/256098.html#Feedback0http://www.aygfsteel.com/yuxh/comments/commentRss/256098.htmlhttp://www.aygfsteel.com/yuxh/services/trackbacks/256098.html先复习下JAVA SERVLET APIQ?br /> servlet API使HTTP直接面向javaq_Q这一意味着java开发h员能一U直观的方式写HTTP server 代码Q这U方式是对HTTP client/server通讯模式的面向对象的抽象。Servlet API有三个核心部分:servlet, request以及response 对象。A servlet is a singleton Java object whose whole purpose is to receive requests and return responses after some arbitrary back-end processing. The request object encapsulates the various details of the request, including the all-important request parameters as submitted via form fields and querystring parameters. The response object includes such key items as the response headers and the output stream that will generate the text of the response. In short, a servlet receives a request object, examines its data, does the appropriate back-end magic, and then writes and returns the response to the client.抽时间看下Servlet SpecificationQ他规定API必须遵守的设计规则(具体实现是由W三方的servlet 容器提供的,容器既可以是独立的,比如tomcatQ也可以是一些更大的application server的一部䆾Q。部|servlet之前Q必L规则打包Q最基础的打包单位是web application。Servlet Specification defines a web application as “a collection of servlets, HTML pages,classes, and other resources.” servlet容器收到h后会军_哪一个servlet处理hQ调用该servlet的service()ҎQ传l他request和response作ؓ参数。Servlet API有三个关键角Ԍservlets,web applications, and the servlet container。一个servlet container可以拥有多个web applications。Servlet APIq提供一些重要的高层功能Q像session机制Q他能把某一客户的相关的h都联pv来(不要忘了HTTP的statelessҎ)QWithout it, we’d be handling cookies and parsing embedded querystring session keys.Q这个没有完全理解,cookies 里是不是嵌入了查询条件参数等?Q。Servlet API直接以一U面向对象抽象的方式装client/sever交换模式Q这h们就不需要亲历亲为的解析HTTPhQ事实上我们收到的是一个整z的用java装的request对象。说q些Q最l是要强调the Servlet API is an infrastructure-level technology in the scope of modern web applications. As infrastructure, servlets provide the solid low-level foundation upon which robust web applications can be built. If you consider the routine needs of a web application, the Servlet API doesn’t attempt to provide solutions for such things. Now that we know what servlets can do,let’s look at what they leave undone. These common tasks of the domain are what a web application framework like Struts 2 will need to address.
        The execution of an interceptor can be broken into three phases: preprocessing, passing control on to the rest of the action invocation by calling invoke(), and postprocessing. Interceptors can also divert workflow by returning a control string instead of calling invoke().They also have access to all key data via the ActionInvocation instance they receive.Ultimately, interceptors can do just about anything.



    yuxh 2009-02-22 22:53 发表评论
    ]]>
    վ֩ģ壺 | ƺ| | ˮ| | կ| ϼ| | | | ƽ| | | | ӽ| | | | | | | | ɽ| ״| Ӣ| | Һ| غ| | ÷ӿ| | ˮ| ɽ| | ƶ| | ɽ| | ֳ| | |