Douyu»áÊÇSSH¹¹¼ÜÓëJSP/Servlet¼¼ÊõµÄÖÕ½áÕßÂð?
DouyuÊÇÒ»ÖÖÍêÈ«²ÉÈ¡JavaÓïÑÔ¿ª·¢µÄ¡¢ÔË×÷ÓÚJVMÒÔÉϵÄÐÂʽ»ù´¡¿ª·¢Æ½Ì¨¡£
ÔÚweb²ã£¬DouyuÍêÈ«ÒÅÆúÁËJSP/Servlet£¬
ÔÚÊý¾Ý¿â·ÃÎʲ㣬Douyu²»ÒÀÀµÓÚÈκÎORM(¶ÔÏñ¹ØϵÕÕÉä)¹¹¼Ü(ÈçHibernate)¡£
Douyu½«JavaÓïÑÔ±àÒëÆ÷¡¢Http·þÎñÆ÷¡¢MVCÔ²Âúµ÷ÕûÔÚÒ»Æð£¬
²îµã¶ù¶ÒÏÖÁËORMÈ«×Ô¶¯»¯£¬Í¬Ê±ÔÚJavaÓïÑÔ²ãÃæÒý³öÁËȨÏÞÖÎÀíÄ£ÐÍ¡£
DouyuÄÚÖõÄJavaÓïÑÔ±àÒëÆ÷»ùÓÚOpenJDK Javac±àÒëÆ÷(b60°æ)£¬
²¢½øÐÐÁËÅú¸ÄºÍÀ©ÕÅ£¬ºÍHttp·þÎñÆ÷×éºÏÒÔºóÄÜÔÚ¿ØÖÆÆ÷²ã·¢»Ó³öÇ¿´óµÄÍþÁ¦£¬
ÄãÖ»ÒªÅú¸ÄJavaÔ´Îļþ£¬ÆäºóË¢ÐÂä¯ÀÀÆ÷¾ÍÄܲ鿴ÔË×÷½á¹û£¬
Óë´Ëͬʱ±àÒëÆ÷Ò²ÊǶÒÏÖORM×Ô¶¯»¯µÄ»ùʯ¡£
DouyuÄÚÖõÄHttp·þÎñÆ÷ÊÇ»ùÓÚNIO¼¼ÊõµÄ£¬
ÊǶÔTomcatÁù¼°com.sun.net.httpserver(Ò»¹²1300¶à¸öJavaÔ´Îļþ)½øÕ¹À«¸«´óµ¶µÄ¸Ä½¨ºóµÃÀ´µÄ£¬
¸Ä½¨ºóµÄHttp·þÎñÆ÷µ±Ç°Î¨ÓÐ60¸öÉÏϵÄÔ´Îļþ£¬Ö§³ÖHttp1.0/1.1ÐÒé¡£
DouyuÄÚÖõÄȨÏÞÖÎÀíÄ£ÐÍÏֽ׶ΰüÔÐÁËЧÄÜȨÏÞ¡¢×Ö¶ÎȨÏÞÁ½À࣬
ЧÄÜȨÏÞÕý³£¶ÔÓ¦¿ØÖÆÆ÷ÀàÖеÄAction²½Ö裬Action²½Öè¿ÉÒÔÓë±íµ¥ÖеÄÐýÅ¥ÁªÏµ¹Øϵ£¬
×Ö¶ÎȨÏÞÄÜͳÖÆ±íµ¥ÖеÄ×Ö¶ÎÊDz»ÊÇ¿ÉÒԲ鿴¡¢Åú¸Ä»òÑڲء£
DouyuÄÚÖõÄORMÒѲîÒ»µã¶ÒÏÖ×Ô¶¯»¯£¬ÄãÖ»Ð뽨¸öÊý¾Ý¿â±í(Èçpet)£¬
ÆäºóÔÚ·þÎñÆ÷ÅäÖÃÎļþÖÐÅ䱸Êý¾Ý¿âÇý¶¯¡¢²¢ÎªÃ¿¸öÊý¾Ý¿âÖ¸¶¨Ò»¸ö°üÃû(Èçmy.oracle.table)£¬
È»ºó¾ÍÄã¿ÉÒÔÔÚÄãµÄJavaÔ´Îļþ¶¥ÓÃimport my.oracle.table.Petµ¼ÈëÄ£ÐÍÖÖPet¡£
Douyu»¹Ö§³Öºá¿ç¶à¸öÊý¾Ý¿âµÄÊÂÒË£¬»¹Ö§³Ö·â´æµã(Savepoint)¡£
DouyuÏîÄ¿Ê×Ò³Ïֽ׶ηÅÔÚ:
http://code.google.com/p/douyu/
µ×ÏÂÊÇһЩ¼òÂԵĴúÂëƬ¶Î:
Hello World
Java´úÂë
1.@Controller
¶þ.public class HelloWorld {
3. public void index(PrintWriter out) {
4. out.println("Hello World!");
5. }
6.}
@Controller
public class HelloWorld {
public void index(PrintWriter out) {
out.println("Hello World!");
}
}
×Ô¶¯ÌáÈ¡±íµ¥²ÎÊý:
Html´úÂë
1.
2. Ãû³Æ:
3. Äê¼Í:
4.
5.
Ãû³Æ:
Äê¼Í:
Java´úÂë
1.@Controller
¶þ.public class User {
3. public void show(String name, int age) {
4. ...
5. }
6.}
@Controller
public class User {
public void show(String name, int age) {
...
}
}
×ÊÁÏÉÏ´«
Html´úÂë
1.
2. ×ÊÁÏÒ»:
Èý.˵Ã÷ :
4.
5.
×ÊÁÏÒ»:
˵Ã÷ :
Java´úÂë
Ò».import com.do
Ïà¹ØÎĵµ£º
filter¹¦ÄÜ.ËüʹÓû§¿ÉÒԸıäÒ»¸ö requestºÍÐÞ¸ÄÒ»¸öresponse. Filter ²»ÊÇÒ»¸öservlet,Ëü²»ÄܲúÉúÒ»¸öresponse,ËüÄܹ»ÔÚÒ»¸örequestµ½´ïservlet֮ǰԤ´¦Àírequest,Ò²¿ÉÒÔÔÚÀ뿪 servletʱ´¦Àíresponse.»»ÖÖ˵·¨,filterÆäʵÊÇÒ»¸ö¡±servlet chaining¡±(servlet Á´). Ò»¸öfilter °üÀ¨:
1. ÔÚservlet±»µ÷ÓÃ֮ǰ½Ø»ñ; ......
a.jspÒ³ÃæÄÚÈÝ£º
%26lt;%@ page language£½"java" import£½"java.util." pageEncoding£½"GB2312"%%26gt;%26lt;form action£½"b.jsp"%26gt; name£º%26lt;input type£½text name£½name%26gt; %26lt;input type£½submit%26gt;%26lt;/form%26gt;
b.jspÒ³ÃæÄÚÈÝ£º
%26lt;%@ page language£½"java" import£½"java.util." pageE ......
Ê×ÏÈ£¬ËµËµJSP/ServletÖеļ¸¸ö±àÂëµÄ×÷Óá£
ÔÚJSP/ServletÖÐÖ÷ÒªÓÐÒÔϼ¸¸öµØ·½¿ÉÒÔÉèÖñàÂ룬pageEncoding="UTF-8"¡¢contentType="text/html;charset=UTF-8"¡¢request.setCharacterEncoding("UTF-8")ºÍresponse.setCharacterEncoding("UTF-8")£¬ÆäÖÐÇ°Á½¸öÖ»ÄÜÓÃÓÚJSPÖУ¬¶øºóÁ½¸ö¿ÉÒÔÓÃÓÚJSPºÍServletÖС£
1¡ ......
ת×Ô£ºhttp://hi.baidu.com/346667002/blog/item/e58edef0d599fcc97831aa18.html
1. ActionContext
ÔÚStruts2¿ª·¢ÖÐ,³ýÁ˽«ÇëÇó²ÎÊý×Ô¶¯ÉèÖõ½ActionµÄ×Ö¶ÎÖÐ,ÎÒÃÇÍùÍùÒ²ÐèÒªÔÚActionÀïÖ±½Ó»ñÈ¡ÇëÇó(Request)»ò»á»°
(Session)µÄһЩÐÅÏ¢,ÉõÖÁÐèÒªÖ±½Ó¶ÔJavaServlet
HttpµÄÇëÇó(HttpServletRequest),ÏìÓ¦(HttpServletRes ......