JSPÖеIJÎÊý´«µÝ·½·¨
£¨1£©ÀûÓÃ<jsp:param name="paramName" value="paramValue"></jsp:param>ÆäÖÐnameΪÓëÊôÐÔÏà¹ØÁªµÄ¹Ø¼ü´Ê£¬valueΪÊôÐÔµÄÖµ¡£
ʾÀý£º´«³£Á¿×Ö·û´®<param name="userName" value="shilei"/>
ʾÀý£º´«±äÁ¿ User user=new User("shilei");//UserÊÇÒ»¸öÀà
<jsp:param name="user" value="<%=user%>"/>//<%=user%>ÀïÃæÀ¨ÆðÀ´µÄÊÇjsp±í´ïʽ
£¨2£©ÀûÓÃsession.setAttribute("attributeName",attribute)»òÕßrequest.setAttribute("attributeName",attribute)
ʾÀý£ºUser user=new User("shilei");
session.setAttribute("userName",user);
£¨3£©¾ÍÏñ´«Í³µÄhtmlÄÇÑùÀûÓÃ±íµ¥×¨µÝ²ÎÊý¡£
ʾÀý£º<form name="loginForm" action="checkLogin.jsp" method="get">
<input type="text" name="username">
<input type="password" name="userpwd">
<input type="submit" value="Ìá½»">
</form>
£¨4£©Ö±½Ó¹ÒÔÚURLºóÃæ¡£Ê¾Àý£ºresponse.sendRedirect("checkLogin.jsp?username="+username+"&userpwd="+userpwd"");
String name=request.getParameter("name");
<a href="welcome.jsp?name=<%=name%>">
£¨5£©ÀûÓÃcookie¶ÔÏóÀ´´«µÝ
Cookie cookie=new Cookie("my","liuliu")
cookie.setMaxage(60*60);(ÒÔÃëΪµ¥Î»)×î´óµÄÉúÃüÖÜÆÚ
response.addCookie(cookie);
Cookie[] cookies=request.getCookies();(¿ÉÒÔͨ¹ý±éÀú´ËÊý×éÀ´·ÃÎÊÖµ)
Ïà¹ØÎĵµ£º
×Ô¶¨Òå±êÇ©ÊÇÈÿª·¢ÈËÔ±´´½¨¿Í»§»¯µÄ±êÇ©,²¢ÇÒÔÚjspÎļþÖÐʹÓÃÕâЩ±êÇ©,ÕâÑù¿ÉÒÔʹjsp´úÂë¸ü¼ò½à!
Ê×ÏÈÕâÀïÏȽéÉÜ´Ó¶¨Òå±êÇ©µ½Ê¹ÓñêÇ©µÄ²½Öè:
1,´´½¨×Ô¶¨Òå±êÇ©´¦ÀíÀà,¼°Ïà¹ØÀà.class ²¢ÇÒ°ÑËûÃǶ¼·ÅÔÚWEB-INF/classesĿ¼ÏÂ
2,´´½¨TLD±êÇ©¿âÃèÊöÎļþ(.tld)Î ......
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µÄ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 ......
Servlet£º
ÔÚServletÖУ¬Ìø×ªÔÚdoGet»òÕßdoPost·½·¨ÖÐʵÏÖ¡£
<1>redirectʵÏÖÒ³ÃæÌø×ª£º
response.sendRedirect("/login.jsp");
·½·¨µÄ²ÎÊýÊÇÏà¶Ô·¾¶£¬É趨Õâ¸ö²ÎÊý¿ÉÒÔÊ¹Ò³ÃæÌø×ªµ½ÈκÎÒ³Ãæ£¬°üÀ¨www.baidu.comµÈÍøÂçÒ³Ãæ¡£
Ìø×ªºóÄã¿ÉÒÔ·¢ÏÖµØÖ·À¸·¢ÉúÁ˱仯¡£
µ×²ãÔÀí£ºÊ¹ÓÃredir ......
·pageContext£ºÌṩ¶ÔÒ³ÃæÊôÐԵķÃÎÊ¡£
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("basePath",basePath);
%>
ʹÓãº
${pageScope}
·reques ......