Java EE Ö®JSP
1.¸ÅÊö
JSPÊÇÒ»ÖÖʵÏÖÆÕͨ¾²Ì¬HTMLºÍ¶¯Ì¬HTML»ìºÏ±àÂëµÄ¼¼Êõ¡£
JSP×îÖջᱻת»»³É±ê×¼µÄServlet£¡£¡£¡
JSPÉè¼ÆµÄÄ¿µÄÔÚÓÚ¼ò»¯±íʾ²ãµÄ±íʾ¡£
JSPÒ³ÃæµÄÆäËû³É·ÖÖ÷ÒªÓÐÈçÏÂÈýÖÖ£º
½Å±¾ÔªËØ
Ö¸Áî
¶¯×÷
ÀýÈ磺
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.*“ %>
...
<HTML>
<BODY>
ÆäËû HTML ÓïÑÔ
<%
·ûºÏJAVA Óï·¨µÄ JAVA Óï¾ä
%>
ÆäËû HTML ÓïÑÔ
</BODY>
</HTML>
2.Óï·¨
JSPÔʼ´úÂëÖаüº¬ÁËJSPÔªËغÍTemplate(Ä£°å) dataÁ½Àà ¡£
Template dataÖ¸µÄÊÇJSPÒýÇæ²»´¦ÀíµÄ²¿·Ö£¬¼´±ê¼Ç<%……%>ÒÔÍâµÄ²¿·Ö£¬ÀýÈç´úÂëÖеÄHTMLµÄÄÚÈÝµÈ £¬ÕâЩÊý¾Ý»áÖ±½Ó´«Ë͵½¿Í»§¶ËµÄä¯ÀÀÆ÷¡£
JSPÔªËØÔòÊÇÖ¸½«ÓÉJSPÒýÇæÖ±½Ó´¦ÀíµÄ²¿·Ö£¬ÕâÒ»²¿·Ö±ØÐë·ûºÏJSPÓï·¨£¬·ñÔò»áµ¼Ö±àÒë´íÎó¡£
JSPÓï·¨·ÖΪÈýÖÖ²»Í¬µÄÀàÐÍ
Ö¸Áî(DIRECTIVE) ÀýÈ磺 <%@ page import=“java.io.*” %>
½Å±¾Óï·¨(SCRIPTING)
¶¯×÷Óï·¨(ACTION) ÀýÈ磺 <jsp:forward>£¬<jsp:getProperty>£¬<jsp:include>
a.½Å±¾Óï·¨°üÀ¨£º
“HTML×¢ÊÍ”:<!— comments -->
JSP Óï·¨¸ñʽÈçÏ£º
<!-- comment [ <%= expression %> ] --> »ò<!-- ×¢ÊÍ [<%= ±í´ïʽ %> ] -->
ÕâÖÖ×¢ÊÍ·¢Ë͵½¿Í»§¶Ë£¬µ«²»Ö±½ÓÏÔʾ£¬ÔÚÔ´´úÂëÖпÉÒԲ鿴µ½¡£
“Òþ²Ø×¢ÊÍ”:<%-- comments --%>
JSP Óï·¨¸ñʽÈçÏ£º
<%-- ×¢ÊÍ --%>
²»·¢Ë͵½¿Í»§¶Ë¡£
“ÉùÃ÷”
JSP Óï·¨¸ñʽÈçÏ£º
<%! declaration; [ declaration; ] ... %> »ò<%! ÉùÃ÷; [ÉùÃ÷; ] ... %>
“±í´ïʽ”
ÓÃÓÚÔÚÒ³ÃæÉÏÊä³öÐÅÏ¢£¬Óï·¨¸ñʽÈçÏ£º
<%= expression %> »ò<%= ±í´ïʽ %>
<%=±í´ïʽ%>Êä³ö±í´ïʽµÄ¼ÆËã½á¹û¡£±í´ïʽÖеıäÁ¿±ØÐëÊÇÇ°ÃæÒÑÉùÃ÷¹ýµÄ±äÁ¿
×¢Ò⣺£¥Ó룽֮¼ä²»ÄÜÓпոñÇÒ±í´ïʽºóÃæ²»ÐèÒª·ÖºÅ¡£
“½Å±¾¶Î”
JSP Óï·¨¸ñʽÈçÏ£º
<% code fragment %> »ò<% ´úÂë %>
b.Ö¸ÁîÔªËØÓï·¨£º
JSPÖ¸ÁîÊÇ´ÓJSPÏòWebÈÝÆ÷·¢Ë͵ÄÏûÏ¢£¬ËüÓÃÀ´ÉèÖÃÒ³ÃæµÄÈ«¾ÖÊôÐÔ£¬ÈçÊä³öÄÚÈÝÀàÐ͵ȡ£
×¢Ò⣺ָÁîµÄ×÷Ó÷¶Î§½öÏÞÓÚ°üº¬Ö¸Áî±¾ÉíµÄJSPÒ³Ãæ¡£
JSPµÄÖ¸Áî¸ñʽΪ£º<%@ Ö¸ÁîÃû ÊôÐÔ="ÊôÐ
Ïà¹ØÎĵµ£º
´ó¼Ò¶¼ËµjavaʹÓõÄ×Ö·û¼¯ÊÇunicode£¬ÄÇôĬÈϱàÂë²»¾ÍÊÇÓ¦¸ÃÊÇUTF8,UTF16Ö®ÀàµÄunicode±àÂëÂð£¿
¿ÉÊǵ÷ÓÃCharset.defaultCharset()µÄ½á¹û²¢·ÇÈç´Ë¡£
import java.nio.charset.Charset;
public class javaCode {
public static void main(String args[])
{
String defaultCharsetName=Charset.defaultChars ......
java³£ÓÃÕýÔò±í´ïʽ
Ö»ÄÜÊäÈëÊý×Ö£º"^[0-9]*$"¡£
Ö»ÄÜÊäÈënλµÄÊý×Ö£º"^\d{n}$"¡£
Ö»ÄÜÊäÈëÖÁÉÙnλµÄÊý×Ö£º"^\d{n,}$"¡£
Ö»ÄÜÊäÈëm~nλµÄÊý×Ö£º¡£"^\d{m,n}$"
Ö»ÄÜÊäÈëÁãºÍ·ÇÁ㿪ͷµÄÊý×Ö£º"^0|[1-9][0-9]*$"¡£
Ö»ÄÜÊäÈëÓÐÁ½Î»Ð¡ÊýµÄÕýʵÊý£º"^[0-9]+( ......
1.µÃµ½µ±Ç°µÄʱ¼ä
Calendar cal = Calendar.getInstance();
String time=formatter.format(cal.getTime());
String strEnd=time.substring(0, 16);// 2007-10-30 09:30
Calendar cal = Calendar.getInstance();
String time=formatter.format(cal.getTime());
String strEnd=time.subst ......
String keyword = request.getParameter("keyword");
String timeRange = request.getParameter("timeRange");
String type = request.getParameter("type");
StringBuffer sql = new StringBuffer();
sql.append("use webstation_leadall s ......
ÔËÐÐ×Ô¼ºÅäÖõÄwebÓ¦Óã¬ÍùÍùÖ»ÄÜ¿´¼ûweblogic±àÒëÖ®ºóµÄclassÎļþ¡£¶ø¿´²»¼û±àÒëÇ°µÄjavaµÄÎļþ¡£ÎªÁ˵÷ÊÔ·½±ã£¬ÎÒÃÇÓÐʱºòÊÇÏë¿´±àÒëÇ°µÄjavaÎļþ¡£
ÔÚweblogic.xmlÖмÓÈë
<jsp-descriptor>
<jsp-param>
<param-name>keepgenerated</param-name>
<param-value>true</par ......