JSP¹ýÂËÆ÷ÔÀí·ÖÎö
http://zhangjunhd.blog.51cto.com/113473/20629
1£®Servlet¹ýÂËÆ÷
1.1 ʲôÊǹýÂËÆ÷
¹ýÂËÆ÷ÊÇÒ»¸ö³ÌÐò£¬ËüÏÈÓÚÓëÖ®Ïà¹ØµÄservlet»òJSPÒ³ÃæÔËÐÐÔÚ·þÎñÆ÷ÉÏ¡£¹ýÂËÆ÷¿É¸½¼Óµ½Ò»¸ö»ò¶à¸öservlet»òJSPÒ³ÃæÉÏ£¬²¢ÇÒ¿ÉÒÔ¼ì²é½øÈëÕâЩ×ÊÔ´µÄÇëÇóÐÅÏ¢¡£ÔÚÕâÖ®ºó£¬¹ýÂËÆ÷¿ÉÒÔ×÷ÈçϵÄÑ¡Ôñ£º
¢ÙÒÔ³£¹æµÄ·½Ê½µ÷ÓÃ×ÊÔ´£¨¼´£¬µ÷ÓÃservlet»òJSPÒ³Ã棩¡£
¢ÚÀûÓÃÐ޸ĹýµÄÇëÇóÐÅÏ¢µ÷ÓÃ×ÊÔ´¡£
¢Ûµ÷ÓÃ×ÊÔ´£¬µ«ÔÚ·¢ËÍÏìÓ¦µ½¿Í»§»úÇ°¶ÔÆä½øÐÐÐ޸ġ£
¢Ü×èÖ¹¸Ã×ÊÔ´µ÷Ó㬴úÖ®ÒÔתµ½ÆäËûµÄ×ÊÔ´£¬·µ»ØÒ»¸öÌض¨µÄ״̬´úÂë»òÉú³ÉÌæ»»Êä³ö¡£
1.2
Servlet¹ýÂËÆ÷µÄ»ù±¾ÔÀí
ÔÚServlet×÷Ϊ¹ýÂËÆ÷ʹÓÃʱ£¬Ëü¿ÉÒÔ¶Ô¿Í»§µÄÇëÇó½øÐд¦Àí¡£´¦ÀíÍê³Éºó£¬Ëü»á½»¸øÏÂÒ»¸ö¹ýÂËÆ÷´¦Àí£¬ÕâÑù£¬¿Í»§µÄÇëÇóÔÚ¹ýÂËÁ´ÀïÖð¸ö´¦Àí£¬Ö±µ½ÇëÇó·¢Ë͵½Ä¿±êΪֹ¡£ÀýÈ磬ijÍøÕ¾ÀïÓÐÌá½»“Ð޸ĵÄ×¢²áÐÅÏ¢”µÄÍøÒ³£¬µ±Óû§ÌîдÍêÐÞ¸ÄÐÅÏ¢²¢Ìá½»ºó£¬·þÎñÆ÷ÔÚ½øÐд¦ÀíʱÐèÒª×öÁ½Ï×÷£ºÅжϿͻ§¶ËµÄ»á»°ÊÇ·ñÓÐЧ£»¶ÔÌá½»µÄÊý¾Ý½øÐÐͳһ±àÂë¡£ÕâÁ½Ï×÷¿ÉÒÔÔÚÓÉÁ½¸ö¹ýÂËÆ÷×é³ÉµÄ¹ýÂËÁ´Àï½øÐд¦Àí¡£µ±¹ýÂËÆ÷´¦Àí³É¹¦ºó£¬°ÑÌá½»µÄÊý¾Ý·¢Ë͵½×îÖÕÄ¿±ê£»Èç¹û¹ýÂËÆ÷´¦Àí²»³É¹¦£¬½«°ÑÊÓͼÅÉ·¢µ½Ö¸¶¨µÄ´íÎóÒ³Ãæ¡£
2£®Servlet¹ýÂËÆ÷¿ª·¢²½Öè
¿ª·¢Servlet¹ýÂËÆ÷µÄ²½ÖèÈçÏ£º
¢Ù±àдʵÏÖFilter½Ó¿ÚµÄServletÀà¡£
¢ÚÔÚweb.xmlÖÐÅäÖÃFilter¡£
¿ª·¢Ò»¸ö¹ýÂËÆ÷ÐèҪʵÏÖFilter½Ó¿Ú£¬Filter½Ó¿Ú¶¨ÒåÁËÒÔÏ·½·¨£º
¢Ùdestory£¨£©ÓÉWebÈÝÆ÷µ÷Ó㬳õʼ»¯´ËFilter¡£
¢Úinit£¨FilterConfig filterConfig£©ÓÉWebÈÝÆ÷µ÷Ó㬳õʼ»¯´ËFilter¡£
¢ÛdoFilter£¨ServletRequest request,ServletResponse response,FilterChain chain£©¾ßÌå¹ýÂË´¦Àí´úÂë¡£
3£®Ò»¸ö¹ýÂËÆ÷¿ò¼ÜʵÀý
SimpleFilter1.java
package com.zj.sample;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class SimpleFilter1 implements Filter {
@SuppressWarnings("unused")
private FilterConfig filterConfig;
public void
Ïà¹ØÎĵµ£º
<%@ page import="java.sql.*,java.io.*" %>
<%
int intPage;//´ýÏÔʾµÄÒ³Âë
int pageSize;//ÿҳÏÔʾµÄÌõÄ¿
int pageCount;//×ÜÒ³Êý
int rowCount;//¼Ç¼×ÜÊý
String strPage;//»ñÈ¡´ýÏÔʾҳÂë
pageSize=12;//ÉèÖÃÿҳÏÔʾÌõÊý
Connection con;//Á¬½Ó¶ÔÏó
Statement stmt;//Êý¾Ý¿â¶ÔÏó
Re ......
1.request¶ÔÏó
¿Í»§¶ËµÄÇëÇóÐÅÏ¢±»·â×°ÔÚrequest¶ÔÏóÖУ¬Í¨¹ýËü²ÅÄÜÁ˽⵽¿Í»§µÄÐèÇó£¬È»ºó×ö³öÏìÓ¦¡£ËüÊÇHttpServletRequestÀàµÄʵÀý¡£
ÐòºÅ ·½ ·¨ ˵ Ã÷
1 object getAttribute(String name) ·µ»ØÖ¸¶¨ÊôÐÔµÄÊôÐÔÖµ
2 Enumeration getAttributeNames() ·µ»ØËùÓпÉÓÃÊôÐÔÃûµÄö¾Ù
3 String getCharacterEncoding() · ......
¶þÕßÇø±ðÊÇ£º
forwardʵ¼ÊÉÏÊÇÇëÇóÔÚ·þÎñÆ÷¶ËÌøת£¬ÇëÇó·½ÊǸÐÖª²»µ½ÕâÖÖÌøתµÄ£¬¶øsendRedirectÊÇÇëÇóÔÚ¿Í»§¶ËÌøת£¨±ÈÈçIE£©£¬µÈÓÚÔٴδӿͻ§¶Ë·¢ËÍÁËÒ»¸öÇëÇó£¬forwardÇé¿öÏÂÓû§ÔÚµØÖ·À¸ÀïÊÇ¿´²»µ½ÌøתºóµÄµØÖ·µÄ£¬sendRedirectÔò¿ÉÒÔ¿´µ½ÐµÄÇëÇóµØÖ·¡£ ......
ʵÏÖÂÛ̳Ê÷ÐͽṹµÄËã·¨ºÜ¶à£¬¾ßÌåÄã¿ÉÒÔÈ¥www.chinaasp.comµÄÈ«ÎÄËÑË÷Öвéѯ¡£ÎÒÏÖÔÚµÄJSPÂÛ̳²ÉÓõÄÒ²Êǵ±ÖеÄÒ»ÖÖ£º²»ÓõݹéʵÏÖÊ÷ÐͽṹµÄËã·¨£¬ÏÖÔÚÎÒ½«ÂÛ̳Ê÷ÐͽṹµÄ¾ßÌåËã·¨ºÍ´ó¼Ò½éÉÜһϣ¬ºÍ´ó¼ÒÒ»Æð½»Á÷¡£
¡¡¡¡1¡¢ÑÝʾ±íµÄ½á¹¹£º
¡¡¡¡¡¡±íÃû£ºmybbslist
¡¡¡¡¡¡×ֶΠ¡¡¡¡¡¡¡¡Êý¾ÝÀàÐÍ¡¡¡¡ËµÃ÷
¡¡¡¡¡¡BBSID ......
´ÓJSPҳʹͼƬÒÔJPEG±àÂëºó´æ´¢ÔÚÖ¸¶¨Îļþ¼ÐÖС£ÕâÖÖJSPÉÏ´«Í¼Æ¬·½Ê½Óë×é¼þÉÏ´«Ïà±ÈËƺõ±¿×¾¶øÓÖ²»ÄܶÔÎļþÊôÐÔ½øÐвÙ×÷£¬µ«µÄÈ·¿ÉÒÔÇáËÉʵÏÖJSPÉÏ´«Í¼Æ¬µÄ¹¦ÄÜ¡£
¡¡¡¡uploadimage1.jspʵÏÖ¹¹½¨Ò»¸ö±íµ¥£¬Ìá½»ÓÃÓÚΪ
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
Str ......