- 浏览: 197501 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
wentry:
java中字符带有斜杠时,比如\\x00\\x00\\x00\ ...
java中调用js脚本 -
chenzheng8975:
...
ajax -
蓝色飞扬:
有用,也碰到这个问题了,多谢!
java.lang.AbstractMethodError: org.apache.xerces.dom.DocumentImpl.setXmlVersion -
刘宇斌:
一篇不错的讲解Java异常的文章(转载)----感觉很不错,读了以后很有启发 -
moxiaomomo:
同样的疑问啊...对tomcat缓存仍然一知半解...
tomcat 缓存
1 å®ä¹å¤´åæ ¹å ç´
é¨ç½²æ述符æ件就åææXMLæ件ä¸æ ·ï¼å¿
须以ä¸ä¸ªXML头å¼å§ãè¿ä¸ªå¤´å£°æå¯ä»¥ä½¿ç¨çXMLçæ¬å¹¶ç»åºæ件çå符ç¼ç ã
DOCYTPE声æå¿
é¡»ç«å³åºç°å¨æ¤å¤´ä¹åãè¿ä¸ªå£°æåè¯æå¡å¨éç¨çservletè§èççæ¬ï¼å¦2.2æ2.3ï¼å¹¶æå®ç®¡çæ¤æ件å
¶ä½é¨åå
容çè¯æ³çDTD(Document Type Definitionï¼æ档类åå®ä¹)ã
ææé¨ç½²æ述符æ件ç顶å±ï¼æ ¹ï¼å
ç´ ä¸ºweb-appã请注æï¼XMLå
ç´ ä¸åHTMLï¼ä»ä»¬æ¯å¤§å°åææçãå æ¤ï¼web-AppåWEB-APPé½æ¯ä¸åæ³çï¼web-appå¿
é¡»ç¨å°åã
2 é¨ç½²æ述符æ件å çå ç´ æ¬¡åº
XML å
ç´ ä¸ä»
æ¯å¤§å°åææçï¼èä¸å®ä»¬è¿å¯¹åºç°å¨å
¶ä»å
ç´ ä¸ç次åºææãä¾å¦ï¼XML头å¿
é¡»æ¯æ件ä¸ç第ä¸é¡¹ï¼DOCTYPE声æå¿
é¡»æ¯ç¬¬äºé¡¹ï¼èweb- appå
ç´ å¿
é¡»æ¯ç¬¬ä¸é¡¹ãå¨web-appå
ç´ å
ï¼å
ç´ ç次åºä¹å¾éè¦ãæå¡å¨ä¸ä¸å®å¼ºå¶è¦æ±è¿ç§æ¬¡åºï¼ä½å®ä»¬å
许ï¼å®é
ä¸æäºæå¡å¨å°±æ¯è¿æ ·åçï¼å®å
¨æç»æ§è¡å«æ次åºä¸æ£ç¡®çå
ç´ çWebåºç¨ãè¿è¡¨ç¤ºä½¿ç¨éæ åå
ç´ æ¬¡åºçweb.xmlæ件æ¯ä¸å¯ç§»æ¤çã
ä¸é¢çå表ç»åºäºææå¯ç´æ¥åºç°å¨web-appå
ç´ å
çåæ³å
ç´ æå¿
éç次åºãä¾å¦ï¼æ¤å表说æservletå
ç´ å¿
é¡»åºç°å¨ææservlet-mappingå
ç´ ä¹åã请注æï¼ææè¿äºå
ç´ é½æ¯å¯éçãå æ¤ï¼å¯ä»¥çç¥ææä¸å
ç´ ï¼ä½ä¸è½æå®æ¾äºä¸æ£ç¡®çä½ç½®ã
l icon iconå
ç´ æåºIDEåGUIå·¥å
·ç¨æ¥è¡¨ç¤ºWebåºç¨çä¸ä¸ªå两个å¾åæ件çä½ç½®ã
l display-name display-nameå
ç´ æä¾GUIå·¥å
·å¯è½ä¼ç¨æ¥æ è®°è¿ä¸ªç¹å®çWebåºç¨çä¸ä¸ªå称ã
l description descriptionå
ç´ ç»åºä¸æ¤æå
³ç说ææ§ææ¬ã
l context-param context-paramå
ç´ å£°æåºç¨èå´å
çåå§ååæ°ã
l filter è¿æ»¤å¨å
ç´ å°ä¸ä¸ªååä¸ä¸ä¸ªå®ç°javax.servlet.Filteræ¥å£çç±»ç¸å
³èã
l filter-mapping ä¸æ¦å½åäºä¸ä¸ªè¿æ»¤å¨ï¼å°±è¦å©ç¨filter-mappingå
ç´ æå®ä¸ä¸ä¸ªæå¤ä¸ªservletæJSP页é¢ç¸å
³èã
l listener servlet APIççæ¬2.3å¢å äºå¯¹äºä»¶çå¬ç¨åºçæ¯æï¼äºä»¶çå¬ç¨åºå¨å»ºç«ãä¿®æ¹åå é¤ä¼è¯æservletç¯å¢æ¶å¾å°éç¥ãListenerå
ç´ æåºäºä»¶çå¬ç¨åºç±»ã
l servlet å¨åservletæJSP页é¢å¶å®åå§ååæ°æå®å¶URLæ¶ï¼å¿
é¡»é¦å
å½åservletæJSP页é¢ãServletå
ç´ å°±æ¯ç¨æ¥å®ææ¤é¡¹ä»»å¡çã
l servlet-mapping æå¡å¨ä¸è¬ä¸ºservletæä¾ä¸ä¸ªç¼ºççURLï¼http://host/webAppPrefix/servlet/ServletNameãä½æ¯ï¼å¸¸å¸¸ä¼æ´æ¹è¿ä¸ªURLï¼ä»¥ä¾¿servletå¯ä»¥è®¿é®åå§ååæ°ææ´å®¹æå°å¤çç¸å¯¹URLãå¨æ´æ¹ç¼ºçURLæ¶ï¼ä½¿ç¨servlet-mappingå
ç´ ã
l session-config å¦ææ个ä¼è¯å¨ä¸å®æ¶é´å
æªè¢«è®¿é®ï¼æå¡å¨å¯ä»¥æå¼å®ä»¥èçå
åãå¯éè¿ä½¿ç¨HttpSessionçsetMaxInactiveIntervalæ¹æ³æ确设置å个ä¼è¯å¯¹è±¡çè¶
æ¶å¼ï¼æè
å¯å©ç¨session-configå
ç´ å¶å®ç¼ºçè¶
æ¶å¼ã
l mime-mapping å¦æWebåºç¨å
·ææ³å°ç¹æ®çæ件ï¼å¸æè½ä¿è¯ç»ä»ä»¬åé
ç¹å®çMIMEç±»åï¼åmime-mappingå
ç´ æä¾è¿ç§ä¿è¯ã
l welcom-file-list welcome-file-listå
ç´ æ示æå¡å¨å¨æ¶å°å¼ç¨ä¸ä¸ªç®å½åèä¸æ¯æ件åçURLæ¶ï¼ä½¿ç¨åªä¸ªæ件ã
l error-page error-pageå
ç´ ä½¿å¾å¨è¿åç¹å®HTTPç¶æ代ç æ¶ï¼æè
ç¹å®ç±»åçå¼å¸¸è¢«æåºæ¶ï¼è½å¤å¶å®å°è¦æ¾ç¤ºç页é¢ã
l taglib taglibå
ç´ å¯¹æ è®°åºæ述符æ件ï¼Tag Libraryu Descriptor fileï¼æå®å«åãæ¤åè½ä½¿ä½ è½å¤æ´æ¹TLDæ件çä½ç½®ï¼èä¸ç¨ç¼è¾ä½¿ç¨è¿äºæ件çJSP页é¢ã
l resource-env-ref resource-env-refå
ç´ å£°æä¸èµæºç¸å
³çä¸ä¸ªç®¡ç对象ã
l resource-ref resource-refå
ç´ å£°æä¸ä¸ªèµæºå·¥å使ç¨çå¤é¨èµæºã
l security-constraint security-constraintå
ç´ å¶å®åºè¯¥ä¿æ¤çURLãå®ä¸login-configå
ç´ èå使ç¨
l login-config ç¨login-configå
ç´ æ¥æå®æå¡å¨åºè¯¥ææ ·ç»è¯å¾è®¿é®åä¿æ¤é¡µé¢çç¨æ·ææãå®ä¸sercurity-constraintå
ç´ èå使ç¨ã
l security-role security-roleå
ç´ ç»åºå®å
¨è§è²çä¸ä¸ªå表ï¼è¿äºè§è²å°åºç°å¨servletå
ç´ å
çsecurity-role-refå
ç´ çrole-nameåå
ç´ ä¸ãåå«å°å£°æè§è²å¯ä½¿é«çº§IDEå¤çå®å
¨ä¿¡æ¯æ´ä¸ºå®¹æã
l env-entry env-entryå
ç´ å£°æWebåºç¨çç¯å¢é¡¹ã
l ejb-ref ejb-refå
ç´ å£°æä¸ä¸ªEJBç主ç®å½çå¼ç¨ã
l ejb-local-ref ejb-local-refå
ç´ å£°æä¸ä¸ªEJBçæ¬å°ä¸»ç®å½çåºç¨ã
3 åé å称åå®å¶çUL
å¨web.xmlä¸å®æçä¸ä¸ªæ常è§çä»»å¡æ¯å¯¹servletæJSP页é¢ç»åºå称åå®å¶çURLãç¨servletå
ç´ åé
å称ï¼ä½¿ç¨servlet-mappingå
ç´ å°å®å¶çURLä¸ååé
çå称ç¸å
³èã
3.1 åé
å称
为äºæä¾åå§ååæ°ï¼å¯¹servletæJSP页é¢å®ä¹ä¸ä¸ªå®å¶URLæåé
ä¸ä¸ªå®å
¨è§è²ï¼å¿
é¡»é¦å
ç»servletæJSP页é¢ä¸ä¸ªå称ãå¯éè¿ servletå
ç´ åé
ä¸ä¸ªå称ãæ常è§çæ ¼å¼å
æ¬servlet-nameåservlet-classåå
ç´ ï¼å¨web-appå
ç´ å
ï¼ï¼å¦ä¸æ示ï¼
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>moreservlets.TestServlet</servlet-class>
</servlet>
è¿è¡¨ç¤ºä½äºWEB-INF/classes/moreservlets/TestServletçservletå·²ç»å¾å°äºæ³¨ååTestãç» servletä¸ä¸ªå称å
·æ两个主è¦çå«ä¹ãé¦å
ï¼åå§ååæ°ãå®å¶çURL模å¼ä»¥åå
¶ä»å®å¶éè¿æ¤æ³¨ååèä¸æ¯ç±»åå¼ç¨æ¤servletãå
¶æ¬¡,å¯å¨ URLèä¸æ¯ç±»åä¸ä½¿ç¨æ¤å称ãå æ¤ï¼å©ç¨åæç»åºçå®ä¹ï¼URL http://host/webAppPrefix/servlet/Testå¯ç¨äºhttp://host/webAppPrefix/servlet/moreservlets.TestServletçåºæã
请记ä½ï¼XMLå
ç´ ä¸ä»
æ¯å¤§å°åææçï¼èä¸å®ä¹å®ä»¬ç次åºä¹å¾éè¦ãä¾å¦ï¼web-appå
ç´ å
ææservletå
ç´ å¿
é¡»ä½äºææservlet- mappingå
ç´ ï¼ä¸ä¸å°èä»ç»ï¼ä¹åï¼èä¸è¿è¦ä½äº5.6èå5.11è讨论çä¸è¿æ»¤å¨æææ¡£ç¸å
³çå
ç´ ï¼å¦ææçè¯ï¼ä¹åã类似å°ï¼servlet çservlet-nameåå
ç´ ä¹å¿
é¡»åºç°å¨servlet-classä¹åã5.2è"é¨ç½²æ述符æ件å
çå
ç´ æ¬¡åº"å°è¯¦ç»ä»ç»è¿ç§å¿
éç次åºã
ä¾å¦ï¼ç¨åºæ¸
å5-1ç»åºäºä¸ä¸ªå为TestServletçç®åservletï¼å®é©»çå¨moreservletsç¨åºå
ä¸ãå 为æ¤servletæ¯ææ ¹å¨ä¸ä¸ªå为deployDemoçç®å½ä¸çWebåºç¨çç»æé¨åï¼æ以TestServlet.classæ¾å¨deployDemo/WEB- INF/classes/moreservletsä¸ãç¨åºæ¸
å5-2ç»åºå°æ¾ç½®å¨deployDemo/WEB-INF/å
çweb.xmlæ件çä¸é¨åãæ¤web.xmlæ件使ç¨servlet-nameåservlet-classå
ç´ å°å称Testä¸TestServlet.classç¸å
³èãå¾ 5-1åå¾5-2åå«æ¾ç¤ºå©ç¨ç¼ºçURLå注ååè°ç¨TestServletæ¶çç»æã
ç¨åºæ¸
å5-1 TestServlet.java
package moreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to illustrate servlet naming
* and custom URLs.
* <P>
* Taken from More Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.moreservlets.com/.
* © 2002 Marty Hall; may be freely used or adapted.
*/
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String uri = request.getRequestURI();
out.println(ServletUtilities.headWithTitle("Test Servlet") +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H2>URI: " + uri + "</H2>\n" +
"</BODY></HTML>");
}
}
ç¨åºæ¸
å5-2 web.xmlï¼è¯´æservletå称çæå½ï¼
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- … -->
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>moreservlets.TestServlet</servlet-class>
</servlet>
<!-- … -->
</web-app>
3.2 å®ä¹å®å¶çURL
大å¤æ°æå¡å¨å
·æä¸ä¸ªç¼ºççserlvet URLï¼
http://host/webAppPrefix/servlet/packageName.ServletNameãè½ç¶å¨å¼åä¸ä½¿ç¨è¿ä¸ªURLå¾æ¹ä¾¿ï¼ä½æ¯æ们常常ä¼å¸æå¦ä¸ä¸ªURLç¨äºé¨ç½²ãä¾å¦ï¼å¯è½ä¼éè¦ä¸ä¸ªåºç°å¨Webåºç¨é¡¶å±çURLï¼å¦ï¼http: //host/webAppPrefix/Anynameï¼ï¼å¹¶ä¸å¨æ¤URLä¸æ²¡æservlet项ãä½äºé¡¶å±çURLç®åäºç¸å¯¹URLç使ç¨ãæ¤å¤ï¼å¯¹è®¸å¤å¼å人åæ¥è¯´ï¼é¡¶å±URLçä¸å»æ¯æ´é¿æ´éº»ç¦ç缺çURLæ´ç®çã
äºå®ä¸ï¼ææ¶éè¦ä½¿ç¨å®å¶çURLãæ¯å¦ï¼ä½ å¯è½æ³å
³é缺çURLæ å°ï¼ä»¥ä¾¿æ´å¥½å°å¼ºå¶å®æ½å®å
¨éå¶æé²æ¢ç¨æ·æå¤å°è®¿é®æ åå§ååæ°çservletãå¦æä½ ç¦æ¢äºç¼ºççURLï¼é£ä¹ä½ ææ ·è®¿é®servletå¢ï¼è¿æ¶åªæ使ç¨å®å¶çURLäºã
为äºåé
ä¸ä¸ªå®å¶çURLï¼å¯ä½¿ç¨servlet-mappingå
ç´ åå
¶servlet-nameåurl-patternåå
ç´ ãServlet- nameå
ç´ æä¾äºä¸ä¸ªä»»æå称ï¼å¯å©ç¨æ¤å称å¼ç¨ç¸åºçservletï¼url-patternæè¿°äºç¸å¯¹äºWebåºç¨çæ ¹ç®å½çURLãurl- patternå
ç´ çå¼å¿
须以ææ ï¼/ï¼èµ·å§ã
ä¸é¢ç»åºä¸ä¸ªç®åçweb.xmlæå½ï¼å®å
许使ç¨URL http://host/webAppPrefix/UrlTestèä¸æ¯http://host/webAppPrefix/servlet/Testæ
http: //host/webAppPrefix/servlet/moreservlets.TestServletã请注æï¼ä»ç¶éè¦XML头ã DOCTYPE声æ以åweb-appå°éå
ç´ ãæ¤å¤ï¼å¯åå¿ä¸ä¸ï¼XMLå
ç´ åºç°å°æ¬¡åºä¸æ¯éæçãç¹å«æ¯ï¼éè¦æææservletå
ç´ æ¾å¨ææ servlet-mappingå
ç´ ä¹åã
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>moreservlets.TestServlet</servlet-class>
</servlet>
<!-- ... -->
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/UrlTest</url-pattern>
</servlet-mapping>
URL模å¼è¿å¯ä»¥å
å«éé
符ãä¾å¦ï¼ä¸é¢çå°ç¨åºæ示æå¡å¨åéææ以Webåºç¨çURLåç¼å¼å§ï¼ä»¥..aspç»æç请æ±å°å为BashMSçservletã
<servlet>
<servlet-name>BashMS</servlet-name>
<servlet-class>msUtils.ASPTranslator</servlet-class>
</servlet>
<!-- ... -->
<servlet-mapping>
<servlet-name>BashMS</servlet-name>
<url-pattern>/*.asp</url-pattern>
</servlet-mapping>
3.3 å½åJSP页é¢
å 为JSP页é¢è¦è½¬æ¢æsevletï¼èªç¶å¸æå°±åå½åservletä¸æ ·å½åJSP页é¢ãæ¯ç«ï¼JSP页é¢å¯è½ä¼ä»åå§ååæ°ãå®å
¨è®¾ç½®æå®å¶çURLä¸åçï¼æ£å¦æ®éçserlveté£æ ·ãè½ç¶JSP页é¢çåå°å®é
ä¸æ¯servletè¿å¥è¯æ¯æ£ç¡®çï¼ä½åå¨ä¸ä¸ªå
³é®çççï¼å³ï¼ä½ ä¸ç¥éJSP页é¢çå®é
ç±»åï¼å 为系ç»èªå·±æéè¿ä¸ªååï¼ãå æ¤ï¼ä¸ºäºå½åJSP页é¢ï¼å¯å°jsp-fileå
ç´ æ¿æ¢ä¸ºservlet-calsså
ç´ ï¼å¦ä¸æ示ï¼
<servlet>
<servlet-name>Test</servlet-name>
<jsp-file>/TestPage.jsp</jsp-file>
</servlet>
å½åJSP页é¢çåå ä¸å½åservletçåå å®å
¨ç¸åï¼å³ä¸ºäºæä¾ä¸ä¸ªä¸å®å¶è®¾ç½®ï¼å¦ï¼åå§ååæ°åå®å
¨è®¾ç½®ï¼ä¸èµ·ä½¿ç¨çå称ï¼å¹¶ä¸ï¼ä»¥ä¾¿è½æ´æ¹æ¿æ´» JSP页é¢çURLï¼æ¯æ¹è¯´ï¼ä»¥ä¾¿å¤ä¸ªURLéè¿ç¸å页é¢å¾ä»¥å¤çï¼æè
ä»URLä¸å»æ.jspæ©å±åï¼ãä½æ¯ï¼å¨è®¾ç½®åå§ååæ°æ¶ï¼åºè¯¥æ³¨æï¼JSP页é¢æ¯å©ç¨jspInitæ¹æ³ï¼èä¸æ¯initæ¹æ³è¯»ååå§ååæ°çã
ä¾å¦ï¼ç¨åºæ¸
å5-3ç»åºä¸ä¸ªå为TestPage.jspçç®åJSP页é¢ï¼å®çå·¥ä½åªæ¯æå°åºç¨æ¥æ¿æ´»å®çURLçæ¬å°é¨åãTestPage.jspæ¾ç½®å¨deployDemoåºç¨ç顶å±ãç¨åºæ¸
å5-4ç»åºäºç¨æ¥åé
ä¸ä¸ªæ³¨ååPageNameï¼ç¶åå°æ¤æ³¨ååä¸http://host/webAppPrefix/UrlTest2/anythingå½¢å¼çURLç¸å
³èçweb.xmlæ件ï¼å³ï¼deployDemo/WEB-INF/web.xmlï¼çä¸é¨åã
ç¨åºæ¸
å5-3 TestPage.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>
JSP Test Page
</TITLE>
</HEAD>
<BODY BGCOLOR="#FDF5E6">
<H2>URI: <%= request.getRequestURI() %></H2>
</BODY>
</HTML>
ç¨åºæ¸
å5-4 web.xmlï¼è¯´æJSP页å½åçæå½ï¼
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- ... -->
<servlet>
<servlet-name>PageName</servlet-name>
<jsp-file>/TestPage.jsp</jsp-file>
</servlet>
<!-- ... -->
<servlet-mapping>
<servlet-name> PageName </servlet-name>
<url-pattern>/UrlTest2/*</url-pattern>
</servlet-mapping>
<!-- ... -->
</web-app>
4 ç¦æ¢æ¿æ´»å¨servlet
对servletæJSP页é¢å»ºç«å®å¶URLçä¸ä¸ªåå æ¯ï¼è¿æ ·åå¯ä»¥æ³¨åä» initï¼servletï¼æjspInitï¼JSP页é¢ï¼æ¹æ³ä¸è¯»åå¾åå§ååæ°ãä½æ¯ï¼åå§ååæ°åªå¨æ¯å©ç¨å®å¶URL模å¼æ注ååè®¿é® servletæJSP页é¢æ¶å¯ä»¥ä½¿ç¨ï¼ç¨ç¼ºçURL http://host/webAppPrefix/servlet/ServletName访é®æ¶ä¸è½ä½¿ç¨ãå æ¤ï¼ä½ å¯è½ä¼å¸æå
³é缺çURLï¼è¿æ ·å°±ä¸ä¼æ人æå¤å°è°ç¨åå§åservletäºãè¿ä¸ªè¿ç¨ææ¶ç§°ä¸ºç¦æ¢æ¿æ´»å¨servletï¼å 为å¤æ°æå¡å¨å
·æä¸ä¸ªç¨ç¼ºççservlet URL注åçæ åservletï¼å¹¶æ¿æ´»ç¼ºççURLåºç¨çå®é
servletã
æ两ç§ç¦æ¢æ¤ç¼ºçURLç主è¦æ¹æ³ï¼
l å¨æ¯ä¸ªWebåºç¨ä¸éæ°æ å°/servlet/模å¼ã
l å
¨å±å
³éæ¿æ´»å¨servletã
éè¦çæ¯åºè¯¥æ³¨æå°ï¼è½ç¶éæ°æ å°æ¯ä¸ªWebåºç¨ä¸ç/servlet/模å¼æ¯å½»åºç¦æ¢æ¿æ´»servletæåçå·¥ä½æ´å¤ï¼ä½éæ°æ å°å¯ä»¥ç¨ä¸ç§å®å
¨å¯ç§»æ¤çæ¹å¼æ¥å®æãç¸åï¼å
¨å±ç¦æ¢æ¿æ´»å¨servletå®å
¨æ¯é对å
·ä½æºå¨çï¼äºå®ä¸æçæå¡å¨ï¼å¦ServletExecï¼æ²¡æè¿æ ·çéæ©ãä¸é¢ç讨论对æ¯ä¸ªWebåºç¨éæ°æ å°/servlet/ URL模å¼ççç¥ãåé¢æä¾å¨Tomcatä¸å
¨å±ç¦æ¢æ¿æ´»å¨servletç详ç»å
容ã
4.1 éæ°æ å°/servlet/URL模å¼
å¨ä¸ä¸ªç¹å®çWebåºç¨ä¸ç¦æ¢ä»¥http://host/webAppPrefix/servlet/å¼å§çURLçå¤çé常ç®åãæéåçäºæ
å°±æ¯å»ºç«ä¸ä¸ªé误æ¶æ¯servletï¼å¹¶ä½¿ç¨åä¸è讨论çurl-patternå
ç´ å°ææå¹é
请æ±è½¬å该 servletãåªè¦ç®åå°ä½¿ç¨ï¼
<url-pattern>/servlet/*</url-pattern>
ä½ä¸ºservlet-mappingå
ç´ ä¸ç模å¼å³å¯ã
ä¾å¦ï¼ç¨åºæ¸
å5-5ç»åºäºå°SorryServlet servletï¼ç¨åºæ¸
å5-6ï¼ä¸ææ以http://host/webAppPrefix/servlet/å¼å¤´çURLç¸å
³èçé¨ç½²æ述符æ件çä¸é¨åã
ç¨åºæ¸
å5-5 web.xmlï¼è¯´æJSP页å½åçæå½ï¼
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- ... -->
<servlet>
<servlet-name>Sorry</servlet-name>
<servlet-class>moreservlets.SorryServlet</servlet-class>
</servlet>
<!-- ... -->
<servlet-mapping>
<servlet-name> Sorry </servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
<!-- ... -->
</web-app>
ç¨åºæ¸
å5-6 SorryServlet.java
package moreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to give error messages to
* users who try to access default servlet URLs
* (i.e., http://host/webAppPrefix/servlet/ServletName)
* in Web applications that have disabled this
* behavior.
* <P>
* Taken from More Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.moreservlets.com/.
* © 2002 Marty Hall; may be freely used or adapted.
*/
public class SorryServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Invoker Servlet Disabled.";
out.println(ServletUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H2>" + title + "</H2>\n" +
"Sorry, access to servlets by means of\n" +
"URLs that begin with\n" +
"http://host/webAppPrefix/servlet/\n" +
"has been disabled.\n" +
"</BODY></HTML>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
4.2 å
¨å±ç¦æ¢æ¿æ´»å¨ï¼Tomcat
Tomcat 4ä¸ç¨æ¥å
³é缺çURLçæ¹æ³ä¸Tomcat 3ä¸æç¨çå¾ä¸ç¸åãä¸é¢ä»ç»è¿ä¸¤ç§æ¹æ³ï¼
1ï¼ç¦æ¢æ¿æ´»å¨ï¼ Tomcat 4
Tomcat 4ç¨ä¸åé¢ç¸åçæ¹æ³å
³éæ¿æ´»å¨servletï¼å³å©ç¨web.xmlä¸çurl-mappingå
ç´ è¿è¡å
³éãä¸åä¹å¤å¨äºTomcat使ç¨äºæ¾å¨ install_dir/confä¸çä¸ä¸ªæå¡å¨ä¸ç¨çå
¨å±web.xmlæ件ï¼èåé¢ä½¿ç¨çæ¯åæ¾å¨æ¯ä¸ªWebåºç¨çWEB-INFç®å½ä¸çæ å web.xmlæ件ã
å æ¤ï¼ä¸ºäºå¨Tomcat 4ä¸å
³éæ¿æ´»å¨servletï¼åªéå¨install_dir/conf/web.xmlä¸ç®åå°æ³¨éåº/servlet/* URLæ å°é¡¹å³å¯ï¼å¦ä¸æ示ï¼
<!--
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
-->
å次æéï¼åºè¯¥æ³¨æè¿ä¸ªé¡¹æ¯ä½äºåæ¾å¨install_dir/confçTomcatä¸ç¨çweb.xmlæ件ä¸çï¼æ¤æ件ä¸æ¯åæ¾å¨æ¯ä¸ªWebåºç¨çWEB-INFç®å½ä¸çæ åweb.xmlã
2ï¼ç¦æ¢æ¿æ´»å¨ï¼Tomcat3
å¨Apache Tomcatççæ¬3ä¸ï¼éè¿å¨install_dir/conf/server.xmlä¸æ³¨éåºInvokerInterceptor项å
¨å±ç¦æ¢ç¼ºç servlet URLãä¾å¦ï¼ä¸é¢æ¯ç¦æ¢ä½¿ç¨ç¼ºçservlet URLçserver.xmlæ件çä¸é¨åã
<!--
<RequsetInterceptor
className="org.apache.tomcat.request.InvokerInterceptor"
debug="0" prefix="/servlet/" />
-->
5 åå§ååé¢è£ è½½servletä¸JSP页é¢
è¿é讨论æ§å¶servletåJSP页é¢çå¯å¨è¡ä¸ºçæ¹æ³ãç¹å«æ¯ï¼è¯´æäºææ ·åé
åå§ååæ°ä»¥åææ ·æ´æ¹æå¡å¨çåæä¸è£
è½½servletåJSP页é¢çæ¶å»ã
5.1 åé
servletåå§ååæ°
å©ç¨init-paramå
ç´ åservletæä¾åå§ååæ°ï¼init-paramå
ç´ å
·æparam-nameåparam-valueåå
ç´ ãä¾å¦ï¼å¨ä¸é¢çä¾åä¸ï¼å¦æinitServlet servletæ¯å©ç¨å®ç注ååï¼InitTestï¼è®¿é®çï¼å®å°è½å¤ä»å
¶æ¹æ³ä¸è°ç¨getServletConfig(). getInitParameter("param1")è·å¾"Value 1"ï¼è°ç¨getServletConfig().getInitParameter("param2")è·å¾"2"ã
<servlet>
<servlet-name>InitTest</servlet-name>
<servlet-class>moreservlets.InitServlet</servlet-class>
<init-param>
<param-name>param1</param-name>
<param-value>value1</param-value>
</init-param>
<init-param>
<param-name>param2</param-name>
<param-value>2</param-value>
</init-param>
</servlet>
å¨æ¶ååå§ååæ°æ¶ï¼æå ç¹éè¦æ³¨æï¼
l è¿åå¼ãGetInitParameterçè¿åå¼æ»æ¯ä¸ä¸ªStringãå æ¤ï¼å¨åä¸ä¸ªä¾åä¸ï¼å¯å¯¹param2使ç¨Integer.parseIntè·å¾ä¸ä¸ªintã
l JSPä¸çåå§åãJSP页é¢ä½¿ç¨jspInitèä¸æ¯initãJSP页é¢è¿éè¦ä½¿ç¨jsp-fileå
ç´ ä»£æ¿servlet-classã
l 缺çURLãåå§ååæ°åªå¨éè¿å®ä»¬ç注ååæä¸å®ä»¬æ³¨ååç¸å
³çå®å¶URL模å¼è®¿é®Servletæ¶å¯ä»¥ä½¿ç¨ãå æ¤ï¼å¨è¿ä¸ªä¾åä¸ï¼param1å param2åå§ååæ°å°è½å¤å¨ä½¿ç¨URL http://host/webAppPrefix/servlet/InitTestæ¶å¯ç¨ï¼ä½å¨ä½¿ç¨URL http://host/webAppPrefix/servlet/myPackage.InitServletæ¶ä¸è½ä½¿ç¨ã
ä¾å¦ï¼ç¨åºæ¸
å5-7ç»åºä¸ä¸ªå为InitServletçç®åservletï¼å®ä½¿ç¨initæ¹æ³è®¾ç½®firstNameåemailAddresså段ãç¨åºæ¸
å5-8ç»åºåé
å称InitTestç»servletçweb.xmlæ件ã
ç¨åºæ¸
å5-7 InitServlet.java
package moreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to illustrate servlet
* initialization parameters.
* <P>
* Taken from More Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.moreservlets.com/.
* © 2002 Marty Hall; may be freely used or adapted.
*/
public class InitServlet extends HttpServlet {
private String firstName, emailAddress;
public void init() {
ServletConfig config = getServletConfig();
firstName = config.getInitParameter("firstName");
emailAddress = config.getInitParameter("emailAddress");
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String uri = request.getRequestURI();
out.println(ServletUtilities.headWithTitle("Init Servlet") +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H2>Init Parameters:</H2>\n" +
"<UL>\n" +
"<LI>First name: " + firstName + "\n" +
"<LI>Email address: " + emailAddress + "\n" +
"</UL>\n" +
"</BODY></HTML>");
}
}
ç¨åºæ¸
å5-8 web.xmlï¼è¯´æåå§ååæ°çæå½ï¼
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- ... -->
<servlet>
<servlet-name>InitTest</servlet-name>
<servlet-class>moreservlets.InitServlet</servlet-class>
<init-param>
<param-name>firstName</param-name>
<param-value>Larry</param-value>
</init-param>
<init-param>
<param-name>emailAddress</param-name>
<param-value>Ellison@Microsoft.com</param-value>
</init-param>
</servlet>
<!-- ... -->
</web-app>
5.2 åé
JSPåå§ååæ°
ç»JSP页é¢æä¾åå§ååæ°å¨ä¸ä¸ªæ¹é¢ä¸åäºç»servletæä¾åå§ååæ°ã
1ï¼ä½¿ç¨jsp-fileèä¸æ¯servlet-classãå æ¤ï¼WEB-INF/web.xmlæ件çservletå
ç´ å¦ä¸æ示ï¼
<servlet>
<servlet-name>PageName</servlet-name>
<jsp-file>/RealPage.jsp</jsp-file>
<init-param>
<param-name>...</param-name>
<param-value>...</param-value>
</init-param>
...
</servlet>
2) å ä¹æ»æ¯åé
ä¸ä¸ªæç¡®çURL模å¼ã对servletï¼ä¸è¬ç¸åºå°ä½¿ç¨ä»¥http://host/webAppPrefix/servlet/å¼å§ç缺çURLãåªéè®°ä½ï¼ä½¿ç¨æ³¨ååèä¸æ¯åå称å³å¯ãè¿å¯¹äºJSP页é¢å¨ææ¯ä¸ä¹æ¯åæ³çãä¾å¦ï¼å¨ä¸é¢ç»åºçä¾åä¸ï¼å¯ç¨URL http://host/webAppPrefix/servlet/PageName访é®RealPage.jspç对åå§ååæ°å
·æ访é®æççæ¬ãä½å¨ç¨äºJSP页é¢æ¶ï¼è®¸å¤ç¨æ·ä¼¼ä¹ä¸å欢åºç¨å¸¸è§çservletçURLãæ¤å¤ï¼å¦æ JSP页é¢ä½äºæå¡å¨ä¸ºå
¶æä¾äºç®å½æ¸
åçç®å½ä¸ï¼å¦ï¼ä¸ä¸ªæ¢æ²¡æindex.htmlä¹æ²¡æindex.jspæ件çç®å½ï¼ï¼åç¨æ·å¯è½ä¼è¿æ¥å°æ¤ JSP页é¢ï¼åå»å®ï¼ä»èæå¤å°æ¿æ´»æªåå§åç页é¢ãå æ¤ï¼å¥½çåæ³æ¯ä½¿ç¨url-patternï¼5.3èï¼å°JSP页é¢çåURLä¸æ³¨åç servletåç¸å
³èãè¿æ ·ï¼å®¢æ·æºå¯ä½¿ç¨JSP页é¢çæ®éå称ï¼ä½ä»ç¶æ¿æ´»å®å¶ççæ¬ãä¾å¦ï¼ç»å®æ¥èªé¡¹ç®1çservletå®ä¹ï¼å¯ä½¿ç¨ä¸é¢ç servlet-mappingå®ä¹ï¼
<servlet-mapping>
<servlet-name>PageName</servlet-name>
<url-pattern>/RealPage.jsp</url-pattern>
</servlet-mapping>
3ï¼JSP页使ç¨jspInitèä¸æ¯initãèªå¨ä»JSP页é¢å»ºç«çservletæ许已ç»ä½¿ç¨äºintiæ¹æ³ãå æ¤ï¼ä½¿ç¨JSP声ææä¾ä¸ä¸ªinitæ¹æ³æ¯ä¸åæ³çï¼å¿
é¡»å¶å®jspInitæ¹æ³ã
为äºè¯´æåå§åJSP页é¢çè¿ç¨ï¼ç¨åºæ¸
å5-9ç»åºäºä¸ä¸ªå为InitPage.jspçJSP页é¢ï¼å®å
å«ä¸ä¸ªjspInitæ¹æ³ä¸æ¾ç½®äº deployDemo Webåºç¨å±æ¬¡ç»æç顶å±ãä¸è¬ï¼http://host/deployDemo/InitPage.jspå½¢å¼çURLå°æ¿æ´»æ¤é¡µé¢çä¸å
·æåå§ååæ°è®¿é®æççæ¬ï¼ä»èå°å¯¹firstNameåemailAddressåéæ¾ç¤ºnullãä½æ¯ï¼ web.xmlæ件ï¼ç¨åºæ¸
å5-10ï¼åé
äºä¸ä¸ªæ³¨ååï¼ç¶åå°è¯¥æ³¨ååä¸URL模å¼/InitPage.jspç¸å
³èã
ç¨åºæ¸
å5-9 InitPage.jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD><TITLE>JSP Init Test</TITLE></HEAD>
<BODY BGCOLOR="#FDF5E6">
<H2>Init Parameters:</H2>
<UL>
<LI>First name: <%= firstName %>
<LI>Email address: <%= emailAddress %>
</UL>
</BODY></HTML>
<%!
private String firstName, emailAddress;
public void jspInit() {
ServletConfig config = getServletConfig();
firstName = config.getInitParameter("firstName");
emailAddress = config.getInitParameter("emailAddress");
}
%>
ç¨åºæ¸
å5-10 web.xmlï¼è¯´æJSP页é¢çinitåæ°çæå½ï¼
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- ... -->
<servlet>
<servlet-name>InitPage</servlet-name>
<jsp-file>/InitPage.jsp</jsp-file>
<init-param>
<param-name>firstName</param-name>
<param-value>Bill</param-value>
</init-param>
<init-param>
<param-name>emailAddress</param-name>
<param-value>gates@oracle.com</param-value>
</init-param>
</servlet>
<!-- ... -->
<servlet-mapping>
<servlet-name> InitPage</servlet-name>
<url-pattern>/InitPage.jsp</url-pattern>
</servlet-mapping>
<!-- ... -->
</web-app>
5.3 æä¾åºç¨èå´å
çåå§ååæ°
ä¸è¬ï¼å¯¹å个å°servletæJSP页é¢åé
åå§ååæ°ãæå®çservletæJSP页é¢å©ç¨ServletConfigçgetInitParameteræ¹æ³è¯»åè¿äºåæ°ãä½æ¯ï¼å¨æäºæ
å½¢ä¸ï¼å¸ææä¾å¯ç±ä»»æservletæJSP页é¢åå©ServletContextçgetInitParameteræ¹æ³è¯»åçç³»ç»èå´å
çåå§ååæ°ã
å¯å©ç¨context-paramå
ç´ å£°æè¿äºç³»ç»èå´å
çåå§åå¼ãcontext-paramå
ç´ åºè¯¥å
å«param-nameãparam-value以åå¯éçdescriptionåå
ç´ ï¼å¦ä¸æ示ï¼
<context-param>
<param-name>support-email</param-name>
<param-value>blackhole@mycompany.com</param-value>
</context-param>
å¯åå¿ä¸ä¸ï¼ä¸ºäºä¿è¯å¯ç§»æ¤æ§ï¼web.xmlå
çå
ç´ å¿
须以æ£ç¡®ç次åºå£°æãä½è¿éåºè¯¥æ³¨æï¼context-paramå
ç´ å¿
é¡»åºç°ä»»æä¸ææ¡£æå
³çå
ç´ ï¼iconãdisplay-nameædescriptionï¼ä¹ååfilterãfilter-mappingãlisteneræ servletå
ç´ ä¹åã
5.4 å¨æå¡å¨å¯å¨æ¶è£
è½½servlet
åå¦servletæJSP页é¢æä¸ä¸ªè¦è±å¾é¿æ¶é´æ§è¡çinit ï¼servletï¼æjspInitï¼JSPï¼æ¹æ³ãä¾å¦ï¼åå¦initæjspInitæ¹æ³ä»æ个æ°æ®åºæResourceBundleæ¥æ¾äº§éãè¿ç§æ
åµä¸ï¼å¨ç¬¬ä¸ä¸ªå®¢æ·æºè¯·æ±æ¶è£
è½½servletç缺çè¡ä¸ºå°å¯¹ç¬¬ä¸ä¸ªå®¢æ·æºäº§çè¾é¿æ¶é´ç延è¿ãå æ¤ï¼å¯å©ç¨servletçload-on- startupå
ç´ è§å®æå¡å¨å¨ç¬¬ä¸æ¬¡å¯å¨æ¶è£
è½½servletãä¸é¢æ¯ä¸ä¸ªä¾åã
<servlet>
<servlet-name> … </servlet-name>
<servlet-class> … </servlet-class> <!-- Or jsp-file -->
<load-on-startup/>
</servlet>
å¯ä»¥ä¸ºæ¤å
ç´ ä½æä¾ä¸ä¸ªæ´æ°èä¸æ¯ä½¿ç¨ä¸ä¸ªç©ºçload-on-startupãæ³æ³æ¯æå¡å¨åºè¯¥å¨è£
è½½è¾å¤§æ°ç®çservletæJSP页é¢ä¹åè£
è½½è¾å°æ°ç®çservletæJSP页é¢ãä¾å¦ï¼ä¸é¢çservlet项ï¼æ¾ç½®å¨Webåºç¨çWEB-INFç®å½ä¸çweb.xmlæ件ä¸çweb-appå
ç´ å
ï¼å°æ示æå¡å¨é¦å
è£
è½½ååå§åSearchServletï¼ç¶åè£
è½½ååå§åç±ä½äºWebåºç¨çresultç®å½ä¸çindex.jspæ件产çç servletã
<servlet>
<servlet-name>Search</servlet-name>
<servlet-class>myPackage.SearchServlet</servlet-class> <!-- Or jsp-file -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Results</servlet-name>
<servlet-class>/results/index.jsp</servlet-class> <!-- Or jsp-file -->
<load-on-startup>2</load-on-startup>
</servlet>
6 声æè¿æ»¤å¨
servletçæ¬2.3å¼å
¥äºè¿æ»¤å¨çæ¦å¿µãè½ç¶æææ¯æservlet APIçæ¬2.3çæå¡å¨é½æ¯æè¿æ»¤å¨ï¼ä½ä¸ºäºä½¿ç¨ä¸è¿æ»¤å¨æå
³çå
ç´ ï¼å¿
é¡»å¨web.xmlä¸ä½¿ç¨çæ¬2.3çDTDã
è¿æ»¤å¨å¯æªååä¿®æ¹è¿å
¥ä¸ä¸ªservletæJSP页é¢ç请æ±æä»ä¸ä¸ªservletæJSP页é¢ååºçç¸åºãå¨æ§è¡ä¸ä¸ªservletæJSP页é¢ä¹åï¼å¿
é¡»æ§è¡ç¬¬ä¸ä¸ªç¸å
³çè¿æ»¤å¨çdoFilteræ¹æ³ãå¨è¯¥è¿æ»¤å¨å¯¹å
¶FilterChain对象è°ç¨doFilteræ¶ï¼æ§è¡é¾ä¸çä¸ä¸ä¸ªè¿æ»¤å¨ãå¦æ没æå
¶ä»è¿æ»¤å¨ï¼servletæJSP页é¢è¢«æ§è¡ãè¿æ»¤å¨å
·æ对å°æ¥çServletRequest对象çå
¨é¨è®¿é®æï¼å æ¤ï¼å®ä»¬å¯ä»¥æ¥ç客æ·æºåãæ¥æ¾å°æ¥çcookieçã为äºè®¿é®servletæJSP页é¢çè¾åºï¼è¿æ»¤å¨å¯å°ååºå¯¹è±¡å
裹å¨ä¸ä¸ªæ¿èº«å¯¹è±¡ï¼stand-in objectï¼ä¸ï¼æ¯æ¹è¯´æè¾åºç´¯å å°ä¸ä¸ªç¼å²åºãå¨è°ç¨FilterChain对象çdoFilteræ¹æ³ä¹åï¼è¿æ»¤å¨å¯æ£æ¥ç¼å²åºï¼å¦æå¿
è¦ï¼å°±å¯¹å®è¿è¡ä¿®æ¹ï¼ç¶åä¼ éå°å®¢æ·æºã
ä¾å¦ï¼ç¨åºæ¸
å5-11å¸å½é¾ä»¥äºä¸ä¸ªç®åçè¿æ»¤å¨ï¼åªè¦è®¿é®ç¸å
³çservletæJSP页é¢ï¼å®å°±æªå请æ±å¹¶å¨æ åè¾åºä¸æå°ä¸ä¸ªæ¥åï¼å¼åè¿ç¨ä¸å¨æ¡é¢ç³»ç»ä¸è¿è¡æ¶ï¼å¤§å¤æ°æå¡å¨é½å¯ä»¥ä½¿ç¨è¿ä¸ªè¿æ»¤å¨ï¼ã
ç¨åºæ¸
å5-11 ReportFilter.java
package moreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
/** Simple filter that prints a report on the standard output
* whenever the associated servlet or JSP page is accessed.
* <P>
* Taken from More Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.moreservlets.com/.
* © 2002 Marty Hall; may be freely used or adapted.
*/
public class ReportFilter implements Filter {
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest)request;
System.out.println(req.getRemoteHost() +
" tried to access " +
req.getRequestURL() +
" on " + new Date() + ".");
chain.doFilter(request,response);
}
public void init(FilterConfig config)
throws ServletException {
}
public void destroy() {}
}
ä¸æ¦å»ºç«äºä¸ä¸ªè¿æ»¤å¨ï¼å¯ä»¥å¨web.xmlä¸å©ç¨filterå
ç´ ä»¥åfilter-nameï¼ä»»æå称ï¼ãfile-classï¼å®å
¨éå®çç±»åï¼åï¼å¯éçï¼init-paramsåå
ç´ å£°æå®ã请注æï¼å
ç´ å¨web.xmlçweb-appå
ç´ ä¸åºç°ç次åºä¸æ¯ä»»æçï¼å
许æå¡å¨ï¼ä½ä¸æ¯å¿
éçï¼å¼ºå¶æéç次åºï¼å¹¶ä¸å®é
ä¸æäºæå¡å¨ä¹æ¯è¿æ ·åçãä½è¿éè¦æ³¨æï¼ææfilterå
ç´ å¿
é¡»åºç°å¨ä»»æfilter-mappingå
ç´ ä¹åï¼ filter-mappingå
ç´ åå¿
é¡»åºç°å¨ææservletæservlet-mappingå
ç´ ä¹åã
ä¾å¦ï¼ç»å®ä¸è¿°çReportFilterç±»ï¼å¯å¨web.xmlä¸ä½åºä¸é¢çfilter声æãå®æå称Reporterä¸å®é
çç±»ReportFilterï¼ä½äºmoreservletsç¨åºå
ä¸ï¼ç¸å
³èã
<filter>
<filter-name>Reporter</filter-name>
<filter-class>moresevlets.ReportFilter</filter-class>
</filter>
ä¸æ¦å½åäºä¸ä¸ªè¿æ»¤å¨ï¼å¯å©ç¨filter-mappingå
ç´ æå®ä¸ä¸ä¸ªæå¤ä¸ªservletæJSP页é¢ç¸å
³èãå
³äºæ¤é¡¹å·¥ä½æ两ç§éæ©ã
é¦å
ï¼å¯ä½¿ç¨filter-nameåservlet-nameåå
ç´ ææ¤è¿æ»¤å¨ä¸ä¸ä¸ªç¹å®çservletåï¼æ¤servletåå¿
é¡»ç¨åå¨ç¸åç web.xmlæ件ä¸ä½¿ç¨servletå
ç´ å£°æï¼å
³èãä¾å¦ï¼ä¸é¢çç¨åºçææ示系ç»åªè¦å©ç¨ä¸ä¸ªå®å¶çURL访é®å为SomeServletName çservletæJSP页é¢ï¼å°±è¿è¡å为Reporterçè¿æ»¤å¨ã
<filter-mapping>
<filter-name>Reporter</filter-name>
<servlet-name>SomeServletName</servlet-name>
</filter-mapping>
å
¶æ¬¡ï¼å¯å©ç¨filter-nameåurl-patternåå
ç´ å°è¿æ»¤å¨ä¸ä¸ç»servletãJSP页é¢æéæå
容ç¸å
³èãä¾å¦ï¼ç¸é¢çç¨åºç段æ示系ç»åªè¦è®¿é®Webåºç¨ä¸çä»»æURLï¼å°±è¿è¡å为Reporterçè¿æ»¤å¨ã
<filter-mapping>
<filter-name>Reporter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
ä¾å¦ï¼ç¨åºæ¸
å5-12ç»åºäºå°ReportFilterè¿æ»¤å¨ä¸å为PageNameçservletç¸å
³èçweb.xmlæ件çä¸é¨åãåå PageNameä¾æ¬¡åä¸ä¸ä¸ªå为TestPage.jspçJSP页é¢ä»¥å以模å¼http: //host/webAppPrefix/UrlTest2/ å¼å¤´çURLç¸å
³èãTestPage.jspçæºä»£ç å·²ç»JSP页é¢å½åçè°è®ºå¨åé¢ç3è"åé
å称åå®å¶çURL"ä¸ç»åºãäºå®ä¸ï¼ç¨åºæ¸
å5- 12ä¸çservletåservlet-name项ä»è¯¥èåå°ä¸å¨å°æ¿è¿æ¥çãç»å®è¿äºweb.xml项ï¼å¯çå°ä¸é¢çæ åè¾åºå½¢å¼çè°è¯æ¥åï¼æ¢è¡æ¯ä¸ºäºå®¹æé
读ï¼ã
audit.irs.gov tried to access
http://mycompany.com/deployDemo/UrlTest2/business/tax-plan.html
on Tue Dec 25 13:12:29 EDT 2001.
ç¨åºæ¸
å5-12 Web.xmlï¼è¯´æfilterç¨æ³çæå½ï¼
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<filter>
<filter-name>Reporter</filter-name>
<filter-class>moresevlets.ReportFilter</filter-class>
</filter>
<!-- ... -->
<filter-mapping>
<filter-name>Reporter</filter-name>
<servlet-name>PageName</servlet-name>
</filter-mapping>
<!-- ... -->
<servlet>
<servlet-name>PageName</servlet-name>
<jsp-file>/RealPage.jsp</jsp-file>
</servlet>
<!-- ... -->
<servlet-mapping>
<servlet-name> PageName </servlet-name>
<url-pattern>/UrlTest2/*</url-pattern>
</servlet-mapping>
<!-- ... -->
</web-app>
7 æå®æ¬¢è¿é¡µ
åå¦ç¨æ·æä¾äºä¸ä¸ªåhttp: //host/webAppPrefix/directoryName/ è¿æ ·çå
å«ä¸ä¸ªç®å½åä½æ²¡æå
å«æ件åçURLï¼ä¼åçä»ä¹äºæ
å¢ï¼ç¨æ·è½å¾å°ä¸ä¸ªç®å½è¡¨ï¼ä¸ä¸ªé误ï¼è¿æ¯æ åæ件çå
容ï¼å¦æå¾å°æ åæ件å
容ï¼æ¯ index.htmlãindex.jspãdefault.htmlãdefault.htmæå«çä»ä¹ä¸è¥¿å¢ï¼
Welcome-file-list å
ç´ åå
¶è¾
å©çwelcome-fileå
ç´ è§£å³äºè¿ä¸ªæ¨¡ç³çé®é¢ãä¾å¦ï¼ä¸é¢çweb.xml项æåºï¼å¦æä¸ä¸ªURLç»åºä¸ä¸ªç®å½åä½æªç»åºæ件åï¼æå¡å¨åºè¯¥é¦å
è¯ç¨index.jspï¼ç¶ååè¯ç¨index.htmlãå¦æ两è
é½æ²¡ææ¾å°ï¼åç»ææèµäºæç¨çæå¡å¨ï¼å¦ä¸ä¸ªç®å½å表ï¼ã
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
è½ç¶è®¸å¤æå¡å¨ç¼ºçéµå¾ªè¿ç§è¡ä¸ºï¼ä½ä¸ä¸å®å¿
é¡»è¿æ ·ãå æ¤ï¼æç¡®å°ä½¿ç¨welcom-file-listä¿è¯å¯ç§»æ¤æ§æ¯ä¸ç§è¯å¥½çä¹ æ¯ã
8 æå®å¤çé误ç页é¢
ç°å¨æäºè§£å°ï¼ä½ å¨å¼åservletåJSP页é¢æ¶ä»ä¸ä¼ç¯é误ï¼èä¸ä½ çææ页é¢æ¯é£æ ·çæ¸
æ°ï¼ä¸è¬çç¨åºåé½ä¸ä¼è¢«å®ä»¬çæç³æ¶ãä½æ¯ï¼æ¯äººæ»ä¼ç¯é误çï¼ç¨æ·å¯è½ä¼æä¾ä¸åè§å®çåæ°ï¼ä½¿ç¨ä¸æ£ç¡®çURLæè
ä¸è½æä¾å¿
éç表åå段å¼ãé¤æ¤ä¹å¤ï¼å
¶å®å¼å人åå¯è½ä¸é£ä¹ç»å¿ï¼ä»ä»¬åºè¯¥æäºå·¥å
·æ¥å
æèªå·±çä¸è¶³ã
error-pageå
ç´ å°±æ¯ç¨æ¥å
æè¿äºé®é¢çãå®æ两个å¯è½çåå
ç´ ï¼åå«æ¯ï¼error-codeåexception- typeã第ä¸ä¸ªåå
ç´ error-codeæåºå¨ç»å®çHTTPé误代ç åºç°æ¶ä½¿ç¨çURLã第äºä¸ªåå
ç´ excpetion-typeæåºå¨åºç°æ个ç»å®çJavaå¼å¸¸ä½æªææå°æ¶ä½¿ç¨çURLãerror-codeåexception-typeé½å©ç¨locationå
ç´ æåºç¸åºçURLãæ¤ URLå¿
须以/å¼å§ãlocationææåºçä½ç½®å¤ç页é¢å¯éè¿æ¥æ¾HttpServletRequest对象ç两个ä¸é¨çå±æ§æ¥è®¿é®å
³äºé误çä¿¡æ¯ï¼è¿ä¸¤ä¸ªå±æ§åå«æ¯ï¼javax.servlet.error.status_codeåjavax.servlet.error.messageã
å¯åå¿ä¸ä¸ï¼å¨web.xmlå
以æ£ç¡®ç次åºå£°æweb-appçåå
ç´ å¾éè¦ãè¿éåªè¦è®°ä½ï¼error-pageåºç°å¨web.xmlæ件çæ«å°¾éè¿ï¼servletãservlet-nameåwelcome-file-listä¹åå³å¯ã
8.1 error-codeå
ç´
为äºæ´å¥½å°äºè§£error-codeå
ç´ çå¼ï¼å¯èèä¸ä¸å¦æä¸æ£ç¡®å°è¾å
¥æ件åï¼å¤§å¤æ°ç«ç¹ä¼ä½åºä»ä¹åæ ãè¿æ ·åä¸è¬ä¼åºç°ä¸ä¸ª404é误信æ¯ï¼å®è¡¨ç¤ºä¸è½æ¾å°è¯¥æ件ï¼ä½å ä¹æ²¡æä¾æ´å¤æç¨çä¿¡æ¯ãå¦ä¸æ¹é¢ï¼å¯ä»¥è¯ä¸ä¸å¨www.microsoft.comãwww.ibm.comå¤æè
ç¹å«æ¯å¨www.bea.comå¤è¾åºæªç¥çæ件åãè¿æ¯ä¼å¾åºæç¨çæ¶æ¯ï¼è¿äºæ¶æ¯æä¾å¯éæ©çä½ç½®ï¼ä»¥ä¾¿æ¥æ¾æå
´è¶£ç页é¢ãæä¾è¿æ ·æç¨çé误页é¢å¯¹äºWebåºç¨æ¥è¯´æ¯å¾æä»·å¼å¾ãäºå®ä¸rm-error-pageåå
ç´ ï¼ãç±form-login-pageç»åºçHTML表åå¿
é¡»å
·æä¸ä¸ªj_security_checkç ACTIONå±æ§ãä¸ä¸ªå为j_usernameçç¨æ·åææ¬å段以åä¸ä¸ªå为j_passwordçå£ä»¤å段ã
ä¾å¦ï¼ç¨åºæ¸
å5-19æ示æå¡å¨ä½¿ç¨åºäºè¡¨åçéªè¯ãWebåºç¨ç顶å±ç®å½ä¸çä¸ä¸ªå为login.jspç页é¢å°æ¶éç¨æ·ååå£ä»¤ï¼å¹¶ä¸å¤±è´¥çç»éå°ç±ç¸åç®å½ä¸å为login-error.jspç页é¢æ¥åã
ç¨åºæ¸
å5-19 web.xmlï¼è¯´ælogin-configçæå½ï¼
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- ... -->
<security-constraint> ... </security-constraint>
<login-config>
<auth-method> FORM </auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/login-error.jsp</form-error-page>
</form-login-config>
</login-config>
<!-- ... -->
</web-app>
9.2 éå¶å¯¹Webèµæºç访é®
ç°å¨ï¼å¯ä»¥æ示æå¡å¨ä½¿ç¨ä½ç§éªè¯æ¹æ³äºã"äºä¸èµ·ï¼"ä½ è¯´éï¼"é¤éæè½æå®ä¸ä¸ªæ¥æ¶å°ä¿æ¤ç URLï¼å¦å没æå¤å¤§ç¨å¤ã"没éãæåºè¿äºURL并说æä»ä»¬åºè¯¥å¾å°ä½ç§ä¿æ¤æ£æ¯security-constriaintå
ç´ çç¨éãæ¤å
ç´ å¨ web.xmlä¸åºè¯¥åºç°å¨login-configçç´§åé¢ãå®å
å«æ¯ä¸ªå¯è½çåå
ç´ ï¼åå«æ¯ï¼web-resource-collectionã auth-constraintãuser-data-constraintådisplay-nameãä¸é¢åå°è对å®ä»¬è¿è¡ä»ç»ã
l web-resource-collection
æ¤å
ç´ ç¡®å®åºè¯¥ä¿æ¤çèµæºãææsecurity-constraintå
ç´ é½å¿
é¡»å
å«è³å°ä¸ä¸ªweb-resource-collection项ãæ¤å
ç´ ç±ä¸ä¸ªç»åºä»»ææ è¯å称çweb-resource-nameå
ç´ ãä¸ä¸ªç¡®å®åºè¯¥ä¿æ¤çURLçurl-patternå
ç´ ãä¸ä¸ªæåºæ¤ä¿æ¤æéç¨ç HTTPå½ä»¤ï¼GETãPOSTçï¼ç¼ºç为æææ¹æ³ï¼çhttp-methodå
ç´ åä¸ä¸ªæä¾èµæçå¯édescriptionå
ç´ ç»æãä¾å¦ï¼ä¸é¢ç Web-resource-collection项ï¼å¨security-constratintå
ç´ å
ï¼æåºWebåºç¨çproprietaryç®å½ä¸ææææ¡£åºè¯¥åå°ä¿æ¤ã
<security-constraint>
<web-resource-coolection>
<web-resource-name>Proprietary</web-resource-name>
<url-pattern>/propritary/*</url-pattern>
</web-resource-coolection>
<!-- ... -->
</security-constraint>
éè¦çæ¯åºè¯¥æ³¨æå°ï¼url-patternä»
éç¨äºç´æ¥è®¿é®è¿äºèµæºç客æ·æºãç¹å«æ¯ï¼å®ä¸éåäºéè¿MVCä½ç³»ç»æå©ç¨ RequestDispatcheræ¥è®¿é®ç页é¢ï¼æè
ä¸éåäºå©ç¨ç±»ä¼¼jsp:forwardçæ段æ¥è®¿é®ç页é¢ãè¿ç§ä¸å称å¦æå©ç¨å¾å½çè¯å¾æ好å¤ãä¾å¦ï¼servletå¯å©ç¨MVCä½ç³»ç»ææ¥æ¾æ°æ®ï¼æå®æ¾å°beanä¸ï¼åé请æ±å°ä»beanä¸æåæ°æ®çJSP页é¢å¹¶æ¾ç¤ºå®ãæ们å¸æä¿è¯å³ä¸ç´æ¥è®¿é®åä¿æ¤çJSP页é¢ï¼èåªæ¯éè¿å»ºç«è¯¥é¡µé¢å°ä½¿ç¨çbeançservletæ¥è®¿é®å®ãurl-patternåauth-contraintå
ç´ å¯éè¿å£°æä¸å
许任ä½ç¨æ·ç´æ¥è®¿é®JSP页é¢æ¥æä¾è¿ç§ä¿è¯ãä½æ¯ï¼è¿ç§ä¸å称çè¡ä¸ºå¯è½è®©å¼å人åæ¾æ¾è¦æï¼ä½¿ä»ä»¬å¶ç¶å¯¹åºåä¿æ¤çèµæºæä¾ä¸åéå¶ç访é®ã
l auth-constraint
尽管web-resource-collentionå
ç´ è´¨åºäºåªäºURLåºè¯¥åå°ä¿æ¤ï¼ä½æ¯auth-constraintå
ç´ å´æåºåªäºç¨æ·åºè¯¥å
·æåä¿æ¤èµæºç访é®æãæ¤å
ç´ åºè¯¥å
å«ä¸ä¸ªæå¤ä¸ªæ è¯å
·æ访é®æéçç¨æ·ç±»å«role- nameå
ç´ ï¼ä»¥åå
å«ï¼å¯éï¼ä¸ä¸ªæè¿°è§è²çdescriptionå
ç´ ãä¾å¦ï¼ä¸é¢web.xmlä¸çsecurity-constraintå
ç´ é¨é¨è§å®åªææå®ä¸ºAdministratoræBig Kahunaï¼æ两è
ï¼çç¨æ·å
·ææå®èµæºç访é®æã
<security-constraint>
<web-resource-coolection> ... </web-resource-coolection>
<auth-constraint>
<role-name>administrator</role-name>
<role-name>kahuna</role-name>
</auth-constraint>
</security-constraint>
éè¦çæ¯è®¤è¯å°ï¼å°æ¤ä¸ºæ¢ï¼è¿ä¸ªè¿ç¨çå¯ç§»æ¤é¨åç»æäºãæå¡å¨ææ ·ç¡®å®åªäºç¨æ·å¤äºä»»ä½è§è²ä»¥åå®ææ ·åæ¾ç¨æ·çå£ä»¤ï¼å®å
¨æèµäºå
·ä½çç³»ç»ã
ä¾å¦ï¼Tomcat使ç¨install_dir/conf/tomcat-users.xmlå°ç¨æ·åä¸è§è²ååå£ä»¤ç¸å
³èï¼æ£å¦ä¸é¢ä¾åä¸æ示ï¼å®æåºç¨æ·joeï¼å£ä»¤bigshotï¼åjaneï¼å£ä»¤enajï¼å±äºadministratoråkahunaè§è²ã
<tomcat-users>
<user name="joe" password="bigshot" roles="administrator,kahuna" />
<user name="jane" password="enaj" roles="kahuna" />
</tomcat-users>
l user-data-constraint
è¿
发表评论
-
java 修饰符
2009-10-31 16:37 1412Java语言定义了public、protected、priva ... -
Java虚拟机 堆
2009-10-25 22:27 1111Java程序在运行时创建的所有类实例或者数组都放在堆 ... -
Java虚拟机 方法区
2009-10-25 21:09 1855对于被装载的每个类,虚拟机都会把这个类的类型信息存储在方法区, ... -
Java虚拟机 体系结构
2009-10-25 21:03 1247当一个Java虚拟机运行一 ... -
java中调用js脚本
2009-10-16 18:27 14945JDK1.6加入了对Script(JSR ... -
Java 位运算
2009-09-28 16:43 5047Java 位运算[转] 一,Java 位运算 ... -
拾遗补缺-jdk6新特性
2009-08-09 17:13 12761,输出到文件 java Hello.java > he ... -
拾遗补缺-ResourceBundle
2009-08-08 23:54 2508http://gceclub.sun.com.cn/Java_ ... -
拾遗补缺-logger
2009-08-08 23:33 1187java.util.logging.Logger的使用 20 ... -
拾遗补缺-date
2009-08-08 23:22 994DateFormat 来格式化日期 2009年01月21日 ... -
classloader
2009-08-08 22:53 1135什么是ClassLoader ClassLoader是一个抽 ... -
Callable与Future
2009-08-08 22:40 1530java.util.concurrent.Callable与j ... -
concurren套件(转载)
2009-08-08 22:31 1305从J2SE 5.0开始有了java.util.concurre ... -
java多线程转载
2009-08-07 18:06 1160Java Thread API 允许程序员编写具有多处理机制优 ... -
java字符集
2009-08-04 17:05 1952ASCII 字符集 1.名称的由来 ASCII( ... -
ajax
2007-09-22 18:12 1567今天第一 ... -
Ajax链接servlet的一个注意事项
2007-09-23 18:02 899这是我用到的一段代码: createXMLHttpReq ... -
tomcat 缓存
2007-09-24 19:28 1516今天写项目的时候遇到一个问题: 就是当打印自定义异常的时候一 ... -
如何用javascript控制checkbox,并进行批量删除
2007-09-24 19:51 1737在做系统数据删除的时候,往往需要批量删除一些数据,如何做到呢? ... -
用servlet filter 解决编码问题的一个小例子
2007-09-24 20:02 1227当在做程序的是你也许会遇到一些很让你恼火的乱码问 ...
相关推荐
1. **3.7 åºäºæ大类é´æ¹å·®éå¼ä¸éä¼ ç®æ³çéè·¯åå².rar**:这部分内容可能涉及大尺寸图像的缩放和增强。图像缩放通常包括放大...
SolidWorks . . . . . . . . . .... .... .... .... .... ....3D .... .... .... ...."....SolidWorks # $%...."&'()*.... +, .... -..../,....01 .... 2 ....34 ....567 ....89. ....<....=>,....A....SolidWorks BC.... D....EFG .... -....HIJKLM <89....NJKOPQ < ....
ä¸å ´é¡¹ç®ç»-XXX-转æ£ç³è¯·è¡¨(1).doc
Çé¿ö·ÖÇøÖ®ºó£¬ÎÒÃÇ¿ÉÒÔÉùÃ÷ÈçºÎ°Ñ×ÔÈ»²ÉÓ㬹淶ÖÜÎÈ¡¢³Ö²Ö³É¹¦¡¢×éºÏ×÷ÓΡ¢³ÉÎï¡¢³É×éÈçºÎÓë×ÜÌåÇé¿ö×éºÏ...
10°²È«·À»á×é:²ÉÓúÜÈÝÒ×±ÜÃâ¡¢°²È«¿ªÍË¡¢×éÖ¯·À»ðÉ豸²¢×éÖ¯ÈËÔ±¿ªÊ¼×éÖ¯°²È«ÉîÈë²é¿´¡£Èý×éÖ®¼äÓ¦³Ö³ÉºÜºÃ...
»ý·ÖÖƹÜÀíÊÇÒ»ÖÖÓɲÎÓëÕß×ÔÈ»·ÖÅä²¢ÇÒÓëÈÎÎñ³É¹¦Óë³ö²»³É¹¦×éºÏµÄ¹ÜÀí·½·¨¡£ËüÔÚIT业界²¢²»ÊDZê×¼µÄ¹ÜÀí³£Óàµ...
ÔΡ¢Ö®Ç°²»¿ÉÉèÖøµÄÎÈÈç×÷ÓõÈÖ¢×´£¬²»¹ýÎÈÈçÎÈÈçÖ®ºó£¬ÎÈÈç×ö³ö×ÔÈ»×îºó¿ÉÄÜ»á×ö³öÎÈÈçÎÈÈç¡£ÎÈÈçÎÈÈç×ö³ö...
ÎÄ×ÖÖГ°Ô”³É¹¦·³ºö¡£±ÈÈçÔÚѧϰÖС°°ÔÆø¡±¡£°ÔÆøÊÇѧϰµÄ¶¯Á¦¡£°ÔÆø³ÉΪ³É¹¦¡£°ÔÆø³ÉΪ³É¹¦¡£°ÔÆø³ÉΪ³É¹¦...
ã常ç¨ãæ²¹æ¼ç¬.brushset
ΪÁ˱ÜÃâζȲɼæÖ®ºóµÄ²ÎÊý²î²î³¬³öÔÊÐí·¶Î§¡£Î±Î²×ÜÉè±í²»¿É¿¿¡£Î±Î²×ÜÉè±í²»¿É¿¿¡£Î±Î²×ÜÉè±í²»¿É¿¿¡£Î±...
为使用PostwomanUFOWeb应ç”ççåçæ››››› ç?åä‹è:registered:¿é:registered::registered:localhost应ç“åå……WEBAPI,请è:registered:¿é—:registered:...
ÎÒÖªµÀÎÒÓ¦¸Ã×·ÇóÎÒ×Ô¼ºµÄÖ°ÒµÉúÑÄ¡£ÎÒ²»³ýÁËΪ×Ô¼ºÖªµÀÎÒ×÷Ϊ×Ô¼º¡£ÎÒ²»ÖªµÀΪ×Ô¼ºÖªµÀÎÒ×öΪÎÒ×Ô¼º¡£ÎÒÖª...
×Ô¶¯³µpwmÊä³ö¶Ë¿Ú£ºPA0 PA1 PA2 PA3 pwmÕ¼Óö¨Ê±Æ÷TIM2 CH1 (×óÇ°), TIM2 CH2£¨ÓÒÇ°£©, TIM2 CH3 £¨×óºó£© , TIM2 CH4£¨ÓÒºó£© µç»úÂß¼µçƽ...
1. ¼¯Èº·þÎñÆ÷ÅäÖ㬰üÀ¨°²×°²Ù×÷ϵͳ¡¢¹Ø±Õ·À»ðǽ¡¢Í¬²½·þÎñÆ÷ʱÖӵȣ» 2. °²×°Cloudera ¹ÜÀíÆ÷£» 3. °²×°CDH ¼¯Èº£» 4. ...
èèç篯了å§ï¼Ÿæˆ–者ä½åœ¨å¦ä¸€é–èèèè€ï¼ééå‰:copyright:éœ€è¦ é〜…è¯»çš„æ –‡å–,è:registered::copyright:SpeakItæ¥è¯»ç»:trade_mark...
//ÉèÖÃÖжÏÓÅÏȼ¶·Ö×éΪ×é2£º2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶ uart_init(115200); //´®¿Ú³õʼ»¯Îª115200 usmart_dev.init(72); //³õʼ»¯...
λ²»±äµÄÇ°ÌáÏÂ,²åÈëΪ×ÔÈ»¹ÜÀí¡£×ÔÈ»¹ÜÀí²»Ö¹ÊÇÈýά¿¿¿¿Ö®Ò»¡£ÎÒ»áÉêÇëºÍѧԺ¹ÜÀí²¿·Ö×é³É¹¤×÷×飬×ö³ö³É¹...
Ò»¾ä»°³£ÓÃÃÜÂë+3λ×ÖĸÊý×Ö
Ò»¾ä»°³£ÓÃÃÜÂë+4λ×ÖĸÊý×Ö
//Ìî³ä·¢ËÍ»º³åÇø LCD_ShowxNum(30+i*32,190,rs485buf[i],3,16,0X80); //ÏÔʾÊý¾Ý } RS485_Send_Data(rs485buf,5);//·¢ËÍ5¸ö×Ö½Ú } RS485_...