JSPµÄ¾Å¸öÒþº¬¶ÔÏó
Ò»¡¢page ¶ÔÏó
page¶ÔÏó´ú±íJSP±¾Éí£¬¸ü׼ȷµØËµËü´ú±íJSP±»×ªÒëºóµÄServlet£¬Ëü¿ÉÒÔµ÷ÓÃServletÀàËù¶¨ÒåµÄ·½·¨¡£
¶þ¡¢config ¶ÔÏó
config ¶ÔÏóÀï´æ·Å×ÅһЩServlet ³õʼµÄÊý¾Ý½á¹¹¡£
config ¶ÔÏóʵÏÖÓÚjavax.servlet.ServletConfig ½Ó¿Ú£¬Ëü¹²ÓÐÏÂÁÐËÄÖÖ·½·¨£º
public String getInitParameter(name)
public java.util.Enumeration getInitParameterNames( )
public ServletContext getServletContext( )
public Sring getServletName( )
Èý¡¢request ¶ÔÏó
request ¶ÔÏó°üº¬ËùÓÐÇëÇóµÄÐÅÏ¢£¬È磺ÇëÇóµÄÀ´Ô´¡¢±êÍ·¡¢cookiesºÍÇëÇóÏà¹ØµÄ²ÎÊýÖµµÈµÈ¡£
request ¶ÔÏóʵÏÖjavax.servlet.http.HttpServletRequest½Ó¿ÚµÄ£¬ËùÌṩµÄ·½·¨¿ÉÒÔ½«Ëü·ÖΪËÄ´óÀࣺ
1.´¢´æºÍÈ¡µÃÊôÐÔ·½·¨£»
void setAttribute(String name, Object value) É趨nameÊôÐÔµÄֵΪvalue
Enumeration getAttributeNamesInScope(int scope) È¡µÃËùÓÐscope ·¶Î§µÄÊôÐÔ
Object getAttribute(String name) È¡µÃname ÊôÐÔµÄÖµ
void removeAttribute(String name) ÒÆ³ýname ÊôÐÔµÄÖµ
2.È¡µÃÇëÇó²ÎÊýµÄ·½·¨
String getParameter(String name) &
Ïà¹ØÎĵµ£º
Ò»Ö±ÒÔÀ´¶ÔJSPÖгöÏÖÂÒÂëµÄÎÊÌâ¶¼ºÜ»ìÂÒ£¬ÏÖ¾¹ý²éÔÄ×ÊÁÏ£¬¶ÔJSPÂÒÂëÕâ¸öÎÊÌâÓбȽÏÉî¿ÌµÄÈÏʶ£¬Ï±ßÊÇÎÒµÄһЩ¸öÈË×ܽᣬϣÍû¸øÍ¬ÑùÃÔ»óµÄÈË´øÀ´°ïÖú¡£ ͬʱÈç¹û²»¶Ô£¬Ï£ÍûµÃµ½ÌáÐÑ£¬¹²Í¬½ø²½¡£
Ê×ÏÈ£¬ËµËµJSP/ServletÖеö±àÂëµÄ×÷Óãº
1.<%@page pageEncoding="UTF-8" %>
×÷Óãº
* ¸æËßJSP±àÒë ......
1£º³¬Á¬½ÓÌø×ª
ÎÒÃÇÔÚ³¬Á¬½ÓµÄʱºò£¬³£³£Á¬½Óµ½Ò»¸öjsp»òÕßAction,±ÈÈç:
XXX
ÕâÑù×ö»áÓÐÒ»¸öÎÊÌ⣺ÔÚtest.jspÖУ¬³ýÄã´«µÝµÄparam1ºÍparam2²ÎÊýÍâ,ÄãÓÃrequest.getParamter()È¡ÈκÎÔÀ´Ò³ÃæµÄ±íµ¥ÔªËض¼»áΪ¿Õ£¬ÕâÊÇÒòΪÕâÖÖ·½Ê½»á²úÉúеÄrequestÉúÃüÖÜÆÚ£¬ÔÚÕâ¸örequestÖÐÖ»»á°üº¬³¬Á¬½Óºó¸úËæµÄ?param1ÕâÖÖ²ÎÊý£¬ Òò´ ......
<project name="jspToServletToClass" default="jsp2servlet2class" basedir=".">
<!-- set global properties for this build -->
<property environment="env" />
<property name="src" location="F:\JspC\src\" />
< ......
ÔÚʹÓÃÊý¾Ý¿âµÄ¹ý³ÌÖУ¬²»¿É±ÜÃâµÄÐèҪʹÓõ½·ÖÒ³µÄ¹¦ÄÜ£¬¿ÉÊÇJDBCµÄ¹æ·¶¶Ô´ËȴûÓкܺõĽâ¾ö¡£¶ÔÓÚÕâ¸öÐèÇóºÜ¶àÅóÓѶ¼ÓÐ×Ô¼ºµÄ½â¾ö·½°¸£¬±ÈÈçʹÓÃVectorµÈ¼¯ºÏÀàÏȱ£´æÈ¡³öµÄÊý¾ÝÔÙ·ÖÒ³¡£µ«ÕâÖÖ·½·¨µÄ¿ÉÓÃÐԺܲÓëJDBC±¾ÉíµÄ½Ó¿ÚÍêÈ«²»Í¬£¬¶Ô²»Í¬ÀàÐ͵Ä×ֶεÄÖ§³ÖÒ²²»ºÃ¡£ÕâÀïÌṩÁËÒ»Ö ......
Ò»Ö±¶ÔServletµÄ¼¸ÖÖÒ³ÃæÌø×ª·½Ê½£¬Àí½âµÄºýÀïºýÍ¿µÄ£¬½ñÌìÔÚÍøÉÏËÑÁËÒ»°Ñ£¬ÕÒµ½Ò»±é±È½ÏºÃµÄ£¬¼ÇÏÂÀ´£¬ÒÔºó¿´¿´¡£
Ìø×ª·ÖÁ½²¿·Ö£¬Ò»ÊÇ·¢ÉúÔÚservlet£¬Ò»ÊÇÔÚJSP£¬ÆäʵJSPÒ²¾ÍÊÇservlet£¬²»¹ý»¹ÊÇÓеã²îÒìµÎ¡£
Servlet£º
µ±È»£¬ÔÚservletÖУ¬Ò»°ãÌø×ª¶¼·¢ÉúÔÚdoGet, doPostµÈ·½·¨ÀïÃæ¡£
1) redirect · ......