Jsp±àÂë¹æ·¶
Jsp±àÂë¹æ·¶
1.1 Îļþºó׺(File Suffixes)
ÎļþÀà±ð ¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡Îļþºó׺
--------------------------------------
JavaÔ´Îļþ¡¡¡¡¡¡¡¡¡¡¡¡¡¡.java
Java×Ö½ÚÂëÎļþ¡¡¡¡¡¡¡¡¡¡.class
¶¯Ì¬Ò³Ãæ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡.jsp
¾²Ì¬Ò³Ãæ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡.html
½Å±¾Îļþ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡.js
1.2 ³£ÓÃÎļþÃû(Common File Names)
ÎļþÃû ¡¡¡¡¡¡ ¡¡¡¡¡¡¡¡¡¡¡¡ ÓÃ;
------------------------------------------------
README¡¡¡¡¡¡¡¡¡¡¡¡ ¸ÅÊöÌض¨Ä¿Â¼ÏÂËùº¬ÄÚÈݵÄÎļþµÄÊ×Ñ¡ÎļþÃû
2 Ëõ½øÅÅ°æ(Indentation)
4¸ö¿Õ¸ñ³£±»×÷ΪËõ½øÅÅ°æµÄÒ»¸öµ¥Î»¡£Ëõ½øµÄÈ·ÇнâÊͲ¢Î´Ïêϸָ¶¨(¿Õ¸ñ vs. ÖƱí·û)¡£Ò»¸öÖƱí·ûµÈÓÚ8¸ö¿Õ¸ñ(¶ø·Ç4¸ö)¡£
3 ×¢ÊÍ(Comments)
Jsp³ÌÐòÓÐÁ½Àà×¢ÊÍ£º¾²Ì¬Ò³Ãæ×¢ÊͺÍJava×¢ÊÍ.
¾²Ì¬Ò³Ãæ×¢ÊÍ: <!— express -->
Jsp×¢ÊÍ: <%-- express --%>
4 JspÓï·¨(Syntax)
¢Ù JSP Element ¡¡¡¡¡¡¡¡
¢Ú Syntax ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
¢Û Interpretation
---------------------------------------------------------------------------------------------
¢Ù JSP Expression
¢Ú <%= expression %>
¢Û Expression is evaluated and placed in output.
---------------------------------------------------------------------------------------------
¢Ù JSP Scriptlet
¢Ú <% code %>
¢Û Code is inserted in service method.
---------------------------------------------------------------------------------------------
¢Ù JSP Declaration
¢Ú <%! code %>
¢Û Code is inserted in body of servlet class, outside of service method.
---------------------------------------------------------------------------------------------
¢Ù JSP page Directive
¢Ú <%@ page att="val" %>
¢Û Directions to the servlet engine about eneral setup.
---------------------------------------------------------------------------------------------
¢Ù JSP include Directive
¢Ú <%@ include file="url" %>
¢Û A file on the local system to be included when the JSP page is translated into a servlet.
---------------------------------------------------------------------------------------------
¢Ù The
Ïà¹ØÎĵµ£º
image.jspÓÃÓÚÉú³ÉÊý×ÖͼƬ
<%@ page contentType="image/jpeg;charset=gb2312" import="java.awt.*,
java.awt.image.*,java.util.*,javax.imageio.*" %>
<%!
Color getRandColor(int fc,int bc){//¸ø¶¨·¶Î§»ñµÃËæ»úÑÕÉ«
Random random = new Rand ......
Ò»¡¢JSPÒ³ÃæÏÔʾÂÒÂë
¶þ¡¢±íµ¥Ìá½»ÖÐÎÄʱ³öÏÖÂÒÂë
Èý¡¢Êý¾Ý¿âÁ¬½Ó
´ó¼ÒÔÚJSPµÄ¿ª·¢¹ý³ÌÖУ¬¾³£³öÏÖÖÐÎÄÂÒÂëµÄÎÊÌ⣬¿ÉÄÜÒ»ÖÁÀ§ÈÅ×ÅÄú£¬ÎÒÏÖÔÚ°ÑÎÒÔÚJSP¿ª·¢ÖÐÓöµ½
µÄÖÐÎÄÂÒÂëµÄÎÊÌâ¼°½â¾ö°ì·¨Ð´³öÀ´¹©´ó¼Ò²Î¿¼¡£
Ò»¡¢JSPÒ³ÃæÏÔʾÂÒÂë
ÏÂÃæµÄÏÔʾҳÃæ(display.jsp)¾Í³öÏÖÂÒÂ룺
<html>
<head>
<tit ......
²»´¦ÀíÌåÄÚÈݵıêÇ©Àí½âÒ»ÏÂͼƬ1
´¦ÀíÌåÄÚÈݱêÇ©Àí½âÌáͼƬ2
1£ºJspWriter out = pageContext.getOut();
2£ºBodyContent bc = this.getBodyContent();
3£ºString input = bc.getString();
4£ºJspWriter out = bc.getEnclosingWriter();
²»´¦ÀíÌåÄÚÈÝ
µÚÒ»ÐдúÂëΪ²»´¦Àí±êÇ©ÌåÄÚÈÝʱÄõ½ÐèÒªµÄÊä³öµ½Ò³ ......
·½·¨Ò»¡¢
login.html
<html>
<head>
<title>Óû§µÇ¼</title>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
</head>
<script language="javascript">
&nbs ......
Ò») °²×°JDK(jdk-1_5_0-windows-i586.exe)£¬Ä¬ÈÏ°²×°£»
(¶þ) °²×°Tomcat(tomcat5.5-installer.exe)£¬Ä¬ÈÏ°²×°£»
* ˳Ðò²»¿ÉÒԵߵ¹ *
(Èý) ²âÊÔ°²×°½á¹û
1. ´ò¿ªä¯ÀÀÆ÷ÊäÈëhttp://localhost:8080£¬Èç¹û³É¹¦£¬Ôò»á¿´µ½»¶ÓÒ³Ãæ¡£´Ëʱ·ÃÎʵÄ·¾¶Îª$tomcat/webapps/root/
(ËÄ) ½¨Á¢ÎÒµÄÕ¾µ ......