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£ºÓÃÓÚ´«µÝÊý¾Ý£¬ÓµÓÐÓëÊý¾ÝÏà
Ïà¹ØÎĵµ£º
½ñÌì×ÜËã°Ñ
response.setHeader("progma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires" ......
jsp:setProperty±êÇ©ÓÃÓÚÉèÖñ»¼ÓÔص½µ±Ç°Ò³ÃæÖеÄJavaBeanÖÐÊôÐÔµÄÖµ
¸ñʽ£º<jsp:setProperty name=? property=? value=?(»òparam=?) />
name£ºÄ³¸öJavaBeanµÄ¶ÔÏóÃû£¬ÓÃÓÚÖ¸¶¨¸øÄĸöJavaBeanÖеÄÊôÐÔ¸³Öµ
property£ºJavaBeanÖеÄij¸öÊôÐÔÃû£¬ÓÃÓÚÖ¸¶¨¸øµ±Ç°JavaBeanÖеÄÄĸöÊôÐÔ¸³Öµ
& ......
JSPÊÇÈÝÒ׳öÏÖÂÒÂëÎÊÌ⣬²»¹ýÄãֻҪעÒâÒÔϼ¸µã¾ÍÒ»¶¨Äܸ㶨 ¿É²Î¿¼http://www.historycreator.com/bbs/2009-10/19/033181872.html
1¡¢±£Ö¤ÄãµÄÎı¾±àÂëÓëÄãËùÆÚÍûµÄ±àÂëÏà·û£¨ÓÃд×Ö°å´ò¿ªÄãµÄÒ³ÃæÈ»ºóÎļþÁí´æΪ£¬ÔÚ±àÂëλÖÃÑ¡ÔñÄãÆÚÍûµÄÎı¾±àÂ룬GB2312¶ÔÓ¦ANSI£¬UTF8µ±È»¶ÔÓÚUTF8ÁË£©
2¡¢±£Ö¤´úÂëÀïÃæµÄÉùÃ÷±àÂëÓëÄ ......
JSP +Tomcat
Êý¾Ý¿â·ÃÎÊ
×÷ÕߣºÁõÖ¾Ô¶
ÔÚÒ»°ãµÄ
Web
ÏîÄ¿¿ª·¢ÖУ¬¶ÔÊý¾Ý¿âµÄ·ÃÎÊÊDZز»¿ÉÉٵģ¬±¾ÎÄÖ÷Òª½éÉÜÁ½ÖÖÔÚ
ʹÓÃ
Tomcat
×÷Ϊ
Web
·þÎñµÄ
JSP
¿ª·¢ÖзÃÎÊÊý¾Ý¿âµÄ·½·¨£¬Ï£ÍûÄܶԸսӴ¥
JSP
¿ª·¢µÄÅóÓÑÓÐËù°ïÖú¡£
ÓÃ
¹ý
.NET
ƽ̨µÄÅóÓÑÓ¦¸ÃÖªµÀ£¬ÏîÄ¿ÖÐÐèÒª·ÃÎÊÊý¾Ý¿âʱ£ ......
ÔÚjspÒ³ÃæÖн«»Ø³µ»»Ðзû´æÈë±íÖз½·¨
1.ÔÚÒ»¸ötextareaÖÐÊäÈëÒ»¶ÎÎÄ×Ö£¬Óл»ÐÐʱ£¬½«»»ÐзûÒ»Æð²åÈëÊý¾Ý¿âÖÐ
ʹÓ÷½·¨ÈçÏ£º
public static String TextToHtml(String sourcestr)
{   ......