Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JSPÓëServletµÄÏ໥ͨÐÅ·½Ê½(Ò»)

     JSPÓëServletÖ®¼äµÄ»á»°¸ú×Ù·½Ê½Óжà¸ö£¬×¢¶¨ËûÃǵÄͨÐÅ·½Ê½ÓжàÖÖ¡£
    ÏÂÃæÏÈÀ´¿´¿´4ÖлỰ¸ú×Ù·½Ê½£º
     Ò»£ºSession
     ´«ËͶˣº
      HttpSession session=request.getSession();
session.setAttribute("username","albert");
session.setAttribute("password","albert");
 
     ½ÓÊնˣº
     String username=(String)session.getAtribute("username");
String password=(String)session.getAtribute("password");
     ¶þ£ºcookie
    
     Cookie cookie=new Cookie("username","albert");
cookie.setMaxAge(24*60*60*60);
//·¢ËÍcookieµ½¿Í»§¶Ë
response.addCookie(cookie);
    
     Cookie[] cookies=request.getCookies();
for(int i=0;i<cookies.length;i++){
Cookie temp=cookie[i];
String key=temp.getName();
String value=temp.getValue();
}
     Èý£ºÒþ²Ø±íµ¥Óò
     <input type="hidden" name="username" value="albert"/>
request.getParameter("username");
     ËÄ£ºURLÖØд
     ¿Í»§¶ËHTML£º
      <form name="login" action="/LoginServlet?username=albert&password=albert">
     ·þÎñÆ÷¶ËServlet:
     String username=request.getParameter("username");
String password=request.getParameter("password");


Ïà¹ØÎĵµ£º

jspÖÐ×Ô¶¨Òå±êÇ©×ܽá(Ò»)_´«Í³±êǩƪ

×Ô¶¨Òå±êÇ©ÊÇÈÿª·¢ÈËÔ±´´½¨¿Í»§»¯µÄ±êÇ©,²¢ÇÒÔÚjspÎļþÖÐʹÓÃÕâЩ±êÇ©,ÕâÑù¿ÉÒÔʹjsp´úÂë¸ü¼ò½à!
 Ê×ÏÈÕâÀïÏȽéÉÜ´Ó¶¨Òå±êÇ©µ½Ê¹ÓñêÇ©µÄ²½Öè:
     1,´´½¨×Ô¶¨Òå±êÇ©´¦ÀíÀà,¼°Ïà¹ØÀà.class ²¢ÇÒ°ÑËûÃǶ¼·ÅÔÚWEB-INF/classesĿ¼ÏÂ
     2,´´½¨TLD±êÇ©¿âÃèÊöÎļþ(.tld)Î ......

JSPÒ³Ãæµ÷ÓÃjsÖÐÎÄÂÒÂë

jspÖеÚÒ»¾ä£º
<%@ page language="java" import="java.sql.*,java.util.*,"  contentType="text/HTML;charset=gb2312" pageEncoding="gb2312"%>
htmlÖмÓÉÏ
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
ͨ³£ÕâÑù¾ÍûÓÐÎÊÌâÁË¡£    .
ÔÙÕߣº µ¼ÈëjsʱºòÉ ......

jsp URI´«µÝ²ÎÊý£¬¶Ô·½½ÓÊÜÊÇÂÒÂë½â¾ö·½·¨

ÕâÖ÷ÒªÊÇtomcatµÄÎÊÌ⣬Ëü»áÔÚ´«Ë͵Äʱºò°Ñ×Ö·û¼¯ÖØбàÒ룬µÈ´«¹ýÈ¥µÄjspÒ³Ãæ½ÓÊܵÄʱºò¾Í»á³öÏÖÂÒÂ룬
²»¹ÜÔÚÒ³ÃæÀïÈçºÎÉèÖÃ×Ö·û¼¯¶¼Ã»°ì·¨½â¾ö£¬Õâʱºò±ØÐë±ØÐëÔÚtomcat°²×°Ä¿Â¼Àï½øÐÐÉèÖã¬
C:\Program Files\apache-tomcat-6.0.14\confĿ¼Ï server.xmlÏ <Connector/>±êÇ©Ï ¼ÓÒ»¾ä URIEncoding="GBK" ¾ÍºÃÁ ......

jsp:forward±êÇ©ºÍresponse.sendRedirect()·½·¨µÄÇø±ð

ÔÚÍøÉÏ¿´µ½Ò»Ð©Ìû×Ó£¬×ܽáÁËһЩÇø±ð£¬¿ÉÒÔ´ÓÒÔϼ¸¸ö·½ÃæÀ´¿´£º
1.´ÓµØÖ·À¸ÏÔʾÀ´Ëµ
forwardÊÇ·þÎñÆ÷ÇëÇó×ÊÔ´,·þÎñÆ÷Ö±½Ó·ÃÎÊÄ¿±êµØÖ·µÄURL,°ÑÄǸöURLµÄÏìÓ¦ÄÚÈݶÁÈ¡¹ýÀ´,È»ºó°ÑÕâЩÄÚÈÝ
ÔÙ·¢¸øä¯ÀÀÆ÷.ä¯ÀÀÆ÷¸ù±¾²»ÖªµÀ·þÎñÆ÷·¢Ë͵ÄÄÚÈÝ´ÓÄÄÀïÀ´µÄ,ËùÒÔËüµÄµØÖ·À¸»¹ÊÇÔ­À´µÄµØÖ·.
redirectÊÇ·þÎñ¶Ë¸ù¾ÝÂß¼­,·¢ËÍÒ»¸ö×´ ......

JSP STRUTS ECLIPSE ±àÂëÎÊÌâ

jspµÄpageEncoding="UTF-8",strutsµÄencoding="UTF-8"£¬eclipse µÄ¹¤×÷Çø¼äµÄ±àÂ뷽ʽÊÇGBK£¬µ«ÊÇÔÚstrutsµÄactionÖлñµÃµÄjsp´«À´µÄÖÐÎÄÖÐÓÐÂÒÂ룬ʹÓÃnew String(sysgkForm.getContent().getBytes("UTF-8"),"GBK")תÂëÒ²²»ÐУ¬×îºó·¢ÏÖÎÊÌâ³öÔÚÁËjspÀïÃæ¡£¼ÓÉÏcontentType="text/html; charset=GBK" ¾ÍºÃÁË¡£
pageEncodi ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ