Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Servlet/JSPѧϰ±Ê¼Ç(2) »ù´¡ÖªÊ¶

Servlet/JSPѧϰ±Ê¼Ç(2)-»ù´¡ÖªÊ¶
 ¹ØÓÚBS½á¹¹(ä¯ÀÀÆ÷-·þÎñÆ÷½á¹¹)¡¢HTTP»ù±¾Ô­ÀíµÈ»ù´¡ÖªÊ¶ÏàÐÅ´ó¼Ò±ÈÎÒÇå³þ£¬ÎҾͲ»·Ï»°ÁË¡£²»ÖªµÀµÄͬѧȥgoogleһϡ£ ʲôÊÇServletºÍJSP ÓÃJava¿ª·¢WebÓ¦ÓóÌÐòʱÓõ½µÄ¼¼ÊõÖ÷ÒªÓÐÁ½ÖÖ£¬¼´ServletºÍJSP¡£ ServletÊÇÔÚ·þÎñÆ÷¶ËÖ´ÐеÄJava³ÌÐò£¬Ò»¸ö±»³ÆΪServletÈÝÆ÷µÄ³ÌÐò£¨Æäʵ¾ÍÊÇ·þÎñÆ÷£©¸ºÔðÖ´ÐÐJava³ÌÐò¡£¶øJSP(Java Server Page)ÔòÊÇÒ»¸öÒ³Ã棬ÓÉJSPÈÝÆ÷¸ºÔðÖ´ÐС£ ServletºÍJSPÁ½Õß×î´óµÄÇø±ð¾ÍÊÇ£¬ServletÒÔJava³ÌÐòΪÖ÷£¬Êä³öHTML´úÂëʱÐèҪʹÓÃout.printlnº¯Êý£¬Ò²¾ÍÊÇ˵JavaÖÐÄÚǶHTML£»¶øJSPÔòÒÔHTMLÒ³ÃæΪÖ÷£¬ÐèҪдJava´úÂëʱÔòÔÚÒ³ÃæÖÐÖ±½Ó²åÈëJava´úÂ룬¼´HTMLÖÐÄÚǶJava¡£µäÐ͵ÄÀý×ÓÈçÏ£º
JSPÎļþ
<html>
<body>
<h1>
<% out.println("JSP"); %>
</h1>
</body>
</html>
Servlet
public class MyServlet ... {
...
out.println("<html>");
out.println("<body>");
out.println("<h1>");
out.println("Servlet);
out.println("</h1>");
out.println("</body>");
out.println("</html>");
}
¿É¼û£¬JSP±ãÓÚÊä³ö£¬¶øServlet±ãÓÚ½øÐÐÂß¼­´¦Àí¡£Òò´Ëʵ¼ÊÓ¦ÓÃÖÐÁ½Õß³£³£½áºÏʹÓ㬸÷˾ÆäÖ°¡£ ¶øTomcat¾ÍÊÇÉÏÃæÌáµ½µÄServletÈÝÆ÷ºÍJSPÈÝÆ÷¡£¸÷¸ö°æ±¾¶ÔServlet/JSPЭÒéÖ§³ÖµÄÇé¿öÈçÏ£º Tomcat°æ±¾ Ö§³ÖServlet Ö§³ÖJSP 6.0.x 2.5 2.1 5.5.x 2.4 2.0 4.1.x 2.3 1.2 3.3.x 2.2 1.1 WebÓ¦ÓóÌÐòµÄ½á¹¹ Tomcat°²×°ºÃÒԺ󣬿ÉÒÔÈ¥¿´¿´tomcatĿ¼ÏµÄwebappsĿ¼¡£Õâ¸öĿ¼¾ÍÊÇÓÃÀ´±£´æWebÓ¦ÓóÌÐòµÄ¡£ ÉÏͼµÄ¸ùĿ¼¾ÍÊÇÓ¦µ±·ÅÖÃÔÚ webapps Ŀ¼ÏµÄĿ¼¡£WEB-INFĿ¼ÎÞ·¨´Óä¯ÀÀÆ÷ÖзÃÎÊ¡£ WEB-INF/classesϱ£´æµÄÊDZàÒëºóµÄJava³ÌÐò(Ö÷ÒªÊÇServlet)£¬WEB-INF/lib ϱ£´æµÄÊÇÔËÐÐʱʹÓõĿâÎļþ(.jarÎļþ)£¬web.xmlÔòÊÇÕû¸öÓ¦ÓóÌÐòµÄÅäÖÃÐÅÏ¢¡£ ÆäËûÎļþÀýÈç .jsp¡¢Í¼Æ¬¡¢Javascript½Å±¾µÈ£¬¶¼¿ÉÒÔÖ±½Ó·Åµ½WebÓ¦ÓóÌÐòµÄ¸ùĿ¼Ï¡£ MVCÄ£ÐÍ ËùνMVCÄ£Ð;ÍÊǽ«Êý¾Ý¡¢Âß¼­´¦Àí¡¢Óû§½çÃæ·ÖÀëµÄÒ»ÖÖ·½·¨¡£ M(Model, Ä£ÐÍ)£ºÓÃÓÚÊý¾Ý´¦Àí¡¢Âß¼­´¦Àí¡£ V(View£¬ÊÓͼ)£ºÓÃÓÚÏÔʾÓû§½çÃæ¡£ C(Controller£¬¿ØÖÆÆ÷)£º¸ù¾Ý¿Í»§¶ËµÄÇëÇó¿ØÖÆÂß¼­×ßÏòºÍ»­Ãæ¡£¶øÔÚJavaÖУ¬MVCÕâÈý¸ö²¿·ÖÔò·Ö±ð¶ÔÓ¦ÓÚ JavaBeans¡¢JSPºÍServlet¡£ M = JavaBeans£ºÓÃÓÚ´«µÝÊý¾Ý£¬ÓµÓÐÓëÊý¾ÝÏà


Ïà¹ØÎĵµ£º

jsp¶ÁÈ¡ÅäÖÃÎļþÂÒÂë½â¾ö

Properties properties = new Properties();
   
    File file = new File(request.getRealPath("/") +"\\WEB-INF\\classes\\configs.properties");
    FileInputStream fiStream = new FileInputStream(file);
    InputStreamRe ......

jspÒ³Ãæ URL´«ÖÐÎIJÎÊýµ½ActionÀïÃæ³öÏÖÂÒÂë

½â¾ö·½·¨£º
µÚÒ»ÖÖ£ºÔÚActionÖÐÓà new String(str.getBytes("ISO8859_1"), "UTF8")£¬½øÐÐתÂ룬ÒòΪ´«µÝµÄʱºò£¬ÖÐÎÄĬÈ˵ÄÊÇISO8859_1
 
µÚ¶þÖÖ£º¿Éͨ¹ýÅäÖÃTOMCATÀ´½â¾ö´ËÎÊÌ⣬¾ßÌå½â¾ö·½·¨ÈçÏ£ºÔÚtomcatµÄserver.xmlÀÕÒµ½<Connector port="8080" useBodyEncodingForURI="true" URIEncoding="utf-8"> ......

applet ǶÈëjsp µÈ´«²ÎÊýÎÊÌâ

СµÜ×î½ü¹«Ë¾×öÒ»¸ö±à¼­Æ÷£¬×îºóÑ¡ÔñÓÃappletС³ÌÐòǶÈëjsp ÖÐ
Ï൱ÓÚÒ»¸ö¿ØÖÆ£¬×ܽá·ÖÏíһϣº
Ö÷ÒªÅöµ½ÒÔÏÂÎÊÌ⣺
1£¬´«²ÎÊýÎÊÌ⣺
applet-->jsp:
<applet code="rubikApp.class" archive="rubik.jar" width="300" height="300">
<param name="beta" ......

jspÔËÐл·¾³µÄÅäÖÃ

      Õâ¶Îʱ¼äÔÚѧϰJSP£¬×ÜÌåÀ´Ëµ£¬JSPѧϰÆðÀ´¸Ð¾õ»¹²»´í£¬²»ÖªµÀÊDz»ÊÇÓÐÁËJAVAµÄ¹¦µ×£¬Ã»¸Õ¸Õ¿ªÊ¼Ñ§Ï°CÓïÑÔµÄʱºòÄÇô³ÔÁ¦¡£²»¹ÜÊÇҪѧϰJSP»¹ÊÇÆäËû±à³ÌÓïÑÔ£¬ÎÒÃǶ¼Ó¦¸ÃÄÜѧ»á×Ô¼ºÊìÁ·µÄ°²×°ºÍÅäÖÃÐèÒªÓõ½µÄ¿ª·¢Èí¼þ¡£ÓÐÁË¿ª·¢Èí¼þ¾Í»áÊ°빦±¶¡£Ð´´úÂëÒ²»á¸ü¿ì½ÝºÍ·½±ã£¬ÓÐЩ¹Ø¼ü´Ê»ò´íÎ ......

jsp´æÈëºÍ¶ÁÈ¡»Ø³µ»»Ðзû

ÔÚjspÒ³ÃæÖн«»Ø³µ»»Ðзû´æÈë±íÖз½·¨
1.ÔÚÒ»¸ötextareaÖÐÊäÈëÒ»¶ÎÎÄ×Ö£¬Óл»ÐÐʱ£¬½«»»ÐзûÒ»Æð²åÈëÊý¾Ý¿âÖÐ
ʹÓ÷½·¨ÈçÏ£º
public   static   String   TextToHtml(String   sourcestr)      
  {       ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ