×ܽ᣺JSPÒ³ÃæimgͼƬ»º´æÎÊÌâÏÖÏó±íÊö¼°ÎÊÌâ½â¾ö
JSPÒ³ÃæimgͼƬ»º´æÎÊÌâÏÖÏó±íÊö¼°ÎÊÌâ½â¾ö
l ÎÊÌâ±íÊö£º
µ±¶Ôº¬ÓÐÍ·ÏñµÄ¿Í·þÈËÔ±ÐÅÏ¢½øÐÐÐÞ¸Ä(º¬¶ÔÍ·ÏñÐÅÏ¢µÄÐÞ¸Ä)ºó£¬ÖØдò¿ªÊý¾ÝÐ޸ĽçÃ棬·¢ÏÖÎı¾ÄÚÈÝÐ޸ijɹ¦£¬¶øÍ·ÏñÄÚÈÝÈÔÈ»ÏÔʾΪÔÀ´µÄÍ·Ïñ——Êý¾Ý¿âÖеĶÔÓ¦ÐÅϢͷÏñËùÔÚ×Ö¶ÎÊý¾ÝÒѾ³É¹¦¸üС£
l Ç°Ì᣺
jspÒ³ÃæÖнøÐÐÁËÒ³Ã滺´æÇå³ý´¦Àí£º
<meta http-equiv="pragma" content="no-cache"/>
<meta http-equiv="cache-control" content="no-cache"/>
<meta http-equiv="expires" content="0"/>
µ±È»£¬Ï±ß3ÐдúÂ빦ÄÜÓëÉϱߵÄ3Ðй¦ÄÜÏàͬ£¬Ò³ÃæÖнöдһ·Ý
<%
response.setHeader("Pragma","No-Cache");
response.setHeader("Cache-Control","No-Cache");
response.setDateHeader("Expires", 0);
%>
l ÎÊÌâÇé¾°ÔÙÏÖ£º
ÔjspÖÐimg srcд·¨£º
<img src="<%=path%>/servlet/customer/personPic?cspId=${cspId}"></img>
ÒªÐ޸ĵÄÊý¾Ý½çÃ棺
ÐÞ¸ÄÊý¾Ýºó£¬ÔٴνøÈë´ËÌõÊý¾ÝµÄÐ޸ĽçÃ棺
·¢ÏÖËäÈ»ÆäËüÎı¾×ֶζ¼½øÐÐÁËÏàÓ¦Ð޸ģ¬µ«ÊÇ“Í·Ïñ”²¿·Ö²¢Ã»ÓÐÐÞ¸ÄΪÎÒÃÇÖ¸¶¨µÄͼƬ(ÈçÏÂͼ,Í·ÏñÈÔÈ»ÏÔʾΪһ¸ö“²æ”µÄÐÎ×´)
²éѯÊý¾Ý¿â£¬·¢ÏÖÊý¾Ý¿âÖеÄÍ·Ïñ¶ÔÓ¦µÄblob×Ö¶ÎÖеÄÊý¾ÝÒѾ¸ü¸ÄΪָ¶¨µÄͼƬ¡£
l ÎÊÌâ½â¾ö(¹²Á½²½)£º
£¨1£©ÐÞ¸Äservlet£ºÔÚ½øÐÐÊý¾Ý¶ÁÈ¡µÄservletÖÐÔö¼ÓͼƬËæ»úÊý´úÂë
//ͼƬËæ»úÊý
double randomNum = Math.random();
request.setAttribute("randomNum", randomNum);
£¨2£©¸üÐÂǰ̨Êý¾ÝÐÞ¸Äjsp£ºÍ¼Æ¬ÏÔʾimg±êÇ©µÄsrcÖÐÔö¼Ó“randomNum”²ÎÊý
<img src="<%=path%>/servlet/customer/personPic?cspId=${cspId}&randomNum=${randomNum}"></img>
ÖØдò¿ªÍ¬Ò»ÈËÔ±µÄÊý¾ÝÐ޸ĽçÃæ——³É¹¦ÏÔʾ¸Õ²Å¸üйýµÄͼƬ£¡£¡
l ÔÀí£º
ÓÉÓÚÔÚimgµÄsrcÖÐÔö¼ÓÁËËæ»úÊý²ÎÊý£¬¶à´Î·ÃÎÊͼƬʱ£¬ä¯ÀÀÆ÷ÈÏΪÊÇ·ÃÎÊÁ˲»Í¬µÄͼƬ·¾¶(»òÕß˵ÊÇ·ÃÎÊÁ˲»Í¬µÄͼƬ£©£¬ä¯ÀÀÆ÷»áÿ´ÎÖØзÃÎÊ·þÎñÆ÷¶ÁȡͼƬ£¬¶ø²»ÔÙ¶ÁÈ¡»º´æÖеÄͼƬ¡£
Ïà¹Ø²Î¿¼£º
JspÒ³ÃæÖйØÓÚ¿Í»§¶ËͼƬ»º´æµÄ½â¾ö
Ïà¹ØÎĵµ£º
²½ÖèÒ»£º±à¼TomcatµÄÅäÖÃÎļþconf/server.xmlÔÚÓÃÓÚ½ÓÊÜ¿Í»§¶ËÓï·¨µÄConnector<connector></connector>±êÇ©ÖÐÌí¼ÓURIEncoding="UTF-8"ÊôÐÔ£¬¸ÃÊôÐÔÓÃÀ´½â¾öGETÖеıàÂëÎÊÌâ¡£
xml ´úÂë
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" / ......
ÔÚJSPÖеÄÈç¹ûʹÓà "Ïà¶Ô·¾¶" ÔòÓпÉÄÜ»á³öÏÖÎÊÌâ.
ÒòΪ ÍøÒ³ÖÐµÄ "Ïà¶Ô·¾¶" , ËûÊÇÏà¶ÔÓÚ "URLÇëÇóµÄµØÖ·" ȥѰÕÒ×ÊÔ´.
ÉÏÃæÕâ¾ä»°ÊÇʲôÒâ˼ÄØ ?
¾Ù¸öÀý×Ó:
¼ÙÈçÎÒÃÇÓÐÒ»¸öÏîÄ¿: MyApp
ÔÚ¸ÃÏîÄ¿ÏÂ, ÓÐÒ»¸öjspÎļþ¼Ð
¸ÃÎļþ¼ÐÏ°üÀ¨:
login.jsp // ......
Ò» Ç°Ìá
Ï£Íû×îеļͼÔÚ¿ªÍ·¸øÄãµÄ±í½¨Á¢²éѯ£º
񡜧mytable
²éѯ£ºcreate or replace view as mytable_view from mytable order by id desc ÆäÖУ¬×îºÃʹÓÃÐòÁкÅcreate sequence mytable_sequence À´×Ô¶¯Ôö¼ÓÄãµÄ¼ ......
//×ܼǼÊý
int count = personDao.getCount();
//ÿҳÏÔʾ5Ìõ
int pageSi ......
ÓõÄÊý¾Ý¿âÊÇmysql
¡¾µÚÒ»ÖÖ·½Ê½£¬ÓÃJSPʵÏÖ¡¿
<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%
//**************************************
& ......