ÔÚJSPÖй²ÏíÊý¾Ý£¬´óÌå·ÖΪ2ÖÐÇé¿ö¡£Ò»ÊÇÔÚͬһ¸öÓû§µÄ²»Í¬Ò³ÃæÖ®¼ä¹²ÏíÊý¾Ý£¬¶þÊÇÔÚ²»Í¬µÄÓû§Ö®¼ä¹²ÏíÊý¾Ý.
¶ÔÓÚͬһ¸öÓû§µÄ»á»°£¬ÒªÏëÔÚ²»Í¬µÄÒ³ÃæÖ®¼ä¹²ÏíÊý¾Ý£¬¿ÉÓÐÒÔϼ¸ÖÖÑ¡Ôñ
¡ñ°ÑÊý¾Ý±£´æÔÚSessionÖУ¨ÕâÊǷdz£³£¼ûµÄ·½Ê½£©¡£
¡ñͨ¹ýCookie.
¡ñͨ¹ýÒþº¬µÄ±íµ¥°ÑÊý¾Ý´«µ½ÏÂÒ»¸öÒ³Ãæ¡£
¡ñͨ¹ýServletContext¶ÔÏó¡£
¡ñͨ¹ýApplication¶ÔÏó¡£
¡ñͨ¹ýÎļþϵͳ»òÕßÊý¾Ý¿â¡£
ÒªÔÚ²»Í¬Óû§Ö®¼ä¹²ÏíÊý¾Ý£¬Í¨³£·½·¨ÊÇ£º
¡ñͨ¹ýServletContext¶ÔÏó¡£
¡ñͨ¹ýApplication¶ÔÏó¡£
¡ñͨ¹ýÎļþϵͳ»òÕßÊý¾Ý¿â¡£ ......
µÚÒ»²½£º½¨Á¢Ò»¸öcode.jspµÄÒ³Ã棬²úÉúËæ»úÂë
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"
import="java.io.*,
java.util.*,
com.sun.image.codec.jpeg.*,
java.awt.*,
java.awt.image.*"%>
<%
String s = "";
int intCount = 0;
/**
* ÑéÖ¤Âë¿í¶È
*/
int width=100;
/**
* ÑéÖ¤Âë¸ß¶È
*/
int height=25;
/**
* ÑéÖ¤Âë× ......
½üÆÚµÄÒ»¸öÏîÄ¿ÐèҪʵÏÖÉãÏñͷͼÏñ²É¼¯£¬¾¹ýһϵÁеÄÕÛÌÚÒÔºó£¬ÖÕÓÚʵÏÖÁËÕâ¸ö¹¦ÄÜ£¬ÏÖÕûÀíһϡ£
±¾Éí¾Íjava¼¼ÊõÀ´Ëµ£¬ÒªÊµÏÖÉãÏñÍ·¶þ´Î¿ª·¢£¬²É¼¯ÉãÏñͷͼƬ£¬ÐèҪʹÓõ½JMF£¬JMFÊʺÏʹÓÃÔÚj2se³ÌÐòµ±ÖУ¬ÎÒÐèÒªÔÚweb³ÌÐòÖе÷ÓÃÉãÏñÍ·£¬ºÜÃ÷ÏÔJMFÊǸ㲻¶¨ÁË£¬Ïë¹ýдһ¸öapplet³ÌÐò£¬Ö»ÊÇÄǶ«Î÷ÒªÇó¿Í»§¶Ë±ØÐëÒªÓÐjre»·¾³£¬Õâ¸ö¶ÔÓÚÎÒÀ´Ëµ²»Ì«ºÏÊÊ£¬Äã×ܲ»ÄÜÖ¸ÍûÓû§·ÃÎÊÄãµÄÍøվʱÏÈÏÂÔØÒ»¸öºÜ´óµÄjreÈ¥°²×°ÒÔºóÔÙÀ´ÔٴηÃÎÊ°É£¿
¼ÈÈ»JMF²»ÊÊÓã¬ÄÇôÎÒÃÇÔÚjavaÏîÄ¿ÖÐÈçºÎʵÏÖ¿ØÖÆÉãÏñÍ·×¥ÅÄÄØ£¿±¾ÉíÔÚwindowsƽ̨ÖÐÎÒÃÇ¿ÉÒÔʹÓÃÊÓƵ²É¼¯¿¨µÈµÄ¶þ´Î¿ª·¢°üȥʵÏÖÊÓƵÊý¾ÝµÄ·ÃÎÊ£¬µ«ÊÇÏÖÔÚµÄÉãÏñÍ·¶¼ÊÇusbµÄ£¬ÉõÖÁÊDZʼDZ¾µçÄÔµÄÏÔʾÆÁÉϾʹøÓÐÉãÏñÍ·£¬ÕâÖÖÇé¿öÏÂʹÓòɼ¯¿¨¶þ´Î¿ª·¢°üµÄ·½°¸ÓÖ²»ÊÊÓã¬Ö»ÄÜ×Ô¼ºÐ´³ÌÐòÈ¥×öÒ»¸öÀàËÆÓÚ“ÉãÏñÍ·ÕÕÏàÈí¼þ”µÄ¶«Î÷£¬¾¹ýһϵÁеķÖÎö£¬×îºóÖÕÓÚʵÏÖÁËÔÚweb³ÌÐòÖе÷ÓÃÉãÏñÍ·£¬¿ÉÒÔͨ¹ýjs´úÂë¿ØÖÆÅÄÕÕ£¬Í¨¹ýajax¼¼ÊõʵÏÖÊý¾ÝµÄÉÏ´«£¬ËäÈ»ÎÒûÓÐÔÚasp.net³ÌÐòÖвâÊÔ£¬µ«ÊÇÓ¦¸ÃÖ§³Ö.net¼¼Êõ£¬Ò²¿ÉÒÔʵÏÖÔÚasp.netµÄÏîÄ¿Öвɼ¯ÉãÏñÍ·Êý¾Ý£¬ÀýÈçÓÃÀ´Í¨¹ýÉãÏñÍ·ÅÄÕÕ£¬ÅÄЩ´óÍ·ÌùµÈ¡£
ÂÞàÂÁËÒ»´ó¶Ñ£¬³ÌÐò·ÅÔÚÁËcsdnµÄÏÂÔØ×ÊÔ´ ......
½üÆÚµÄÒ»¸öÏîÄ¿ÐèҪʵÏÖÉãÏñͷͼÏñ²É¼¯£¬¾¹ýһϵÁеÄÕÛÌÚÒÔºó£¬ÖÕÓÚʵÏÖÁËÕâ¸ö¹¦ÄÜ£¬ÏÖÕûÀíһϡ£
±¾Éí¾Íjava¼¼ÊõÀ´Ëµ£¬ÒªÊµÏÖÉãÏñÍ·¶þ´Î¿ª·¢£¬²É¼¯ÉãÏñͷͼƬ£¬ÐèҪʹÓõ½JMF£¬JMFÊʺÏʹÓÃÔÚj2se³ÌÐòµ±ÖУ¬ÎÒÐèÒªÔÚweb³ÌÐòÖе÷ÓÃÉãÏñÍ·£¬ºÜÃ÷ÏÔJMFÊǸ㲻¶¨ÁË£¬Ïë¹ýдһ¸öapplet³ÌÐò£¬Ö»ÊÇÄǶ«Î÷ÒªÇó¿Í»§¶Ë±ØÐëÒªÓÐjre»·¾³£¬Õâ¸ö¶ÔÓÚÎÒÀ´Ëµ²»Ì«ºÏÊÊ£¬Äã×ܲ»ÄÜÖ¸ÍûÓû§·ÃÎÊÄãµÄÍøվʱÏÈÏÂÔØÒ»¸öºÜ´óµÄjreÈ¥°²×°ÒÔºóÔÙÀ´ÔٴηÃÎÊ°É£¿
¼ÈÈ»JMF²»ÊÊÓã¬ÄÇôÎÒÃÇÔÚjavaÏîÄ¿ÖÐÈçºÎʵÏÖ¿ØÖÆÉãÏñÍ·×¥ÅÄÄØ£¿±¾ÉíÔÚwindowsƽ̨ÖÐÎÒÃÇ¿ÉÒÔʹÓÃÊÓƵ²É¼¯¿¨µÈµÄ¶þ´Î¿ª·¢°üȥʵÏÖÊÓƵÊý¾ÝµÄ·ÃÎÊ£¬µ«ÊÇÏÖÔÚµÄÉãÏñÍ·¶¼ÊÇusbµÄ£¬ÉõÖÁÊDZʼDZ¾µçÄÔµÄÏÔʾÆÁÉϾʹøÓÐÉãÏñÍ·£¬ÕâÖÖÇé¿öÏÂʹÓòɼ¯¿¨¶þ´Î¿ª·¢°üµÄ·½°¸ÓÖ²»ÊÊÓã¬Ö»ÄÜ×Ô¼ºÐ´³ÌÐòÈ¥×öÒ»¸öÀàËÆÓÚ“ÉãÏñÍ·ÕÕÏàÈí¼þ”µÄ¶«Î÷£¬¾¹ýһϵÁеķÖÎö£¬×îºóÖÕÓÚʵÏÖÁËÔÚweb³ÌÐòÖе÷ÓÃÉãÏñÍ·£¬¿ÉÒÔͨ¹ýjs´úÂë¿ØÖÆÅÄÕÕ£¬Í¨¹ýajax¼¼ÊõʵÏÖÊý¾ÝµÄÉÏ´«£¬ËäÈ»ÎÒûÓÐÔÚasp.net³ÌÐòÖвâÊÔ£¬µ«ÊÇÓ¦¸ÃÖ§³Ö.net¼¼Êõ£¬Ò²¿ÉÒÔʵÏÖÔÚasp.netµÄÏîÄ¿Öвɼ¯ÉãÏñÍ·Êý¾Ý£¬ÀýÈçÓÃÀ´Í¨¹ýÉãÏñÍ·ÅÄÕÕ£¬ÅÄЩ´óÍ·ÌùµÈ¡£
ÂÞàÂÁËÒ»´ó¶Ñ£¬³ÌÐò·ÅÔÚÁËcsdnµÄÏÂÔØ×ÊÔ´ ......
1.²¿ÊðÈýÖÖ·½Ê½£º
(1) ÔÚserver.xmlµÄHost±êÇ©ÄÚн¨Ò»¸öContext±êÇ©
<Context path="/learn1" reloadable="true" docBase="E:\work\tech\project\learn1\WebRoot" workDir="E:\work\tech\project\learn1\WebRoot\work" />
* workDirÊÇÖ¸Tomcat½âÎöJspת»»ÎªJavaÎļþ£¬²¢±àÒëΪclass´æ·ÅµÄÎļþ¼Ð£¬ÉèÖÃÔÚÏîÄ¿Îļþ¼ÐÀïÃ棬¿ÉÒÔ±ÜÃâÒÆÖ²µ½ÆäËûµØ·½Ê״ζÁÈ¡jspÎļþÐèÒªÖØнâÎö ¡£Ò»°ã¸ñʽ£ºÏîÄ¿Îļþ¼Ð\work
(2) ·ÅÔÚtomcatµÄwebappsÏÂ
(3) ÔÚtomcatµÄconf\Catalina\localhostϽ¨Á¢Ò»Îļþ <·ÃÎÊ·¾¶>.xml, ÄÚÈÝͬ(1)
......
ÔÚ¹ÜÀí¹¤¾ßÀïÃæÓÐÊý¾ÝÔ´ Ñ¡ÔñsqlÊý¾ÝÔ´
ÔÚ´úÂëÖУº
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:Ybz");
Statement stat=con.createStatement();
ResultSet rs=stat.executeQuery("select * from [case] ");
//»òÕß
// PreparedStateme ......
ÔÚ¹ÜÀí¹¤¾ßÀïÃæÓÐÊý¾ÝÔ´ Ñ¡ÔñsqlÊý¾ÝÔ´
ÔÚ´úÂëÖУº
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:Ybz");
Statement stat=con.createStatement();
ResultSet rs=stat.executeQuery("select * from [case] ");
//»òÕß
// PreparedStateme ......
1.request¶ÔÏó
¿Í»§¶ËµÄÇëÇóÐÅÏ¢±»·â×°ÔÚrequest¶ÔÏóÖУ¬Í¨¹ýËü²ÅÄÜÁ˽⵽¿Í»§µÄÐèÇó£¬È»ºó×ö³öÏìÓ¦¡£ËüÊÇHttpServletRequestÀàµÄʵÀý¡£
ÐòºÅ ·½ ·¨ ˵ Ã÷
1 object getAttribute(String name) ·µ»ØÖ¸¶¨ÊôÐÔµÄÊôÐÔÖµ
2 Enumeration getAttributeNames() ·µ»ØËùÓпÉÓÃÊôÐÔÃûµÄö¾Ù
3 String getCharacterEncoding() ·µ»Ø×Ö·û±àÂ뷽ʽ
4 int getContentLength() ·µ»ØÇëÇóÌåµÄ³¤¶È£¨ÒÔ×Ö½ÚÊý£©
5 String getContentType() µÃµ½ÇëÇóÌåµÄMIMEÀàÐÍ
6 ServletInputStream getInputStream() µÃµ½ÇëÇóÌåÖÐÒ»ÐеĶþ½øÖÆÁ÷
7 String getParameter(String name) ·µ»ØnameÖ¸¶¨²ÎÊýµÄ²ÎÊýÖµ
8 Enumeration getParameterNames() ·µ»Ø¿ÉÓòÎÊýÃûµÄö¾Ù
9 String[] getParameterValues(String name) ·µ»Ø°üº¬²ÎÊýnameµÄËùÓÐÖµµÄÊý×é
10 String getProtocol() ·µ»ØÇëÇóÓõÄÐÒéÀàÐͼ°°æ±¾ºÅ
11 String getScheme() ·µ»ØÇëÇóÓõļƻ®Ãû,Èç:http.https¼°ftpµÈ
12 String getServerName() ·µ»Ø½ÓÊÜÇëÇóµÄ·þÎñÆ÷Ö÷»úÃû
13 int getServerPort() ·µ»Ø·þÎñÆ÷½ÓÊÜ´ËÇëÇóËùÓõĶ˿ںÅ
14 BufferedReader getReader() ·µ»Ø½âÂë¹ýÁ˵ÄÇëÇóÌå
15 String getRemoteAddr() · ......