JSPÎÊ´ð¼¯
1¡¢ÈçºÎ»ìºÏʹÓÃJspºÍSSI #include?
ÔÚJSPÖпÉÒÔʹÓÃÈçÏ·½Ê½°üº¬´¿HTML£º
µ«ÊÇÈç¹ûdata.incÖаüº¬JSP CODE £¬ÎÒÃÇ¿ÉÒÔʹÓãº
2¡¢ÈçºÎÖ´ÐÐÒ»¸öḬ̈߳²È«µÄJSP?
Ö»ÐèÔö¼ÓÈçÏÂÖ¸Áî
3¡¢JSPÈçºÎ´¦ÀíHTML FORMÖеÄÊý¾Ý?
ͨ¹ýÄÚÖõÄrequest¶ÔÏó¼´¿É£¬ÈçÏ£º
String item = request.getParameter("item");
int howMany = new Integer(request.getParameter("units")).intValue();
4¡¢ÔÚJSPÈçºÎ°üº¬Ò»¸ö¾²Ì¬Îļþ?
¾²Ì¬°üº¬ÈçÏ£º
¶¯Ì¬°üº¬ÈçÏ£º
5¡¢ÔÚJSPÖÐÈçºÎʹÓÃ×¢ÊÍ?
Ö÷ÒªÓÐËÄÖз½·¨£º
1¡£
2¡£//
3¡£/**Óë**/
4¡£
6¡¢ÔÚJSPÖÐÈçºÎÖ´ÐÐä¯ÀÀÖض¨Ïò?
ʹÓÃÈçÏ·½Ê½¼´¿É£ºresponse.sendRedirect("http://ybwen.home.chinaren.com/index.html");
Ò²ÄÜÎïÀíµØ¸Ä±äHTTP HEADERÊôÐÔ£¬ÈçÏ£º
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn="/newpath/index.html";
response.setHeader("Location",newLocn);
7¡¢ÈçºÎ·ÀÖ¹ÔÚJSP»òSERVLETÖеÄÊä³ö²»±»BROWSER±£´æÔÚCACHEÖÐ?
°ÑÈçϽű¾¼ÓÈëµ½JSPÎļþµÄ¿ªÊ¼¼´¿É£º
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
8¡¢ÔÚJSPÖÐÈçºÎÉèÖÃCOOKIE?
COOKIEÊÇ×÷ΪHTTP HEADERµÄÒ»²¿·Ö±»·¢Ë͵ģ¬ÈçÏ·½·¨¼´¿ÉÉèÖãº
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);
9¡¢ÔÚJSPÖÐÈçºÎɾ³ýÒ»¸öCOOKIE?
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);
10¡¢ÔÚÒ»¸öJSPµÄÇëÇó´¦ÀíÖÐÈçºÎÍ£Ö¹JSPµÄÖ´ÐÐ
ÈçÏÂÀý£º
if (request.getParameter("wen") != null) {
// do something
} else {
return;
}
11¡¢ÔÚJSPÖÐÈçºÎ¶¨Òå·½·¨
Äã¿ÉÒÔ¶¨Òå·½·¨£¬µ«ÊÇÄã²»ÄÜÖ±½Ó·ÃÎÊJSPµÄÄÚÖöÔÏ󣬶øÊÇͨ¹ý²ÎÊýµÄ·½·¨´«µÝ¡£ÈçÏ£º
public String howBadfrom(HttpServletRequest req) {
HttpSession ses = req.getSession();
...
return req.getRemoteHost();
}
out.print("in general,lao lee is not baddie ");
12¡¢Èç¹ûBROWSERÒѹرÕÁËCOOKIES£¬ÔÚJSPÖÐÎÒÈçºÎ´ò¿ªSESSIONÀ´¸ú×Ù
ʹÓÃURLÖØд¼´¿É£¬ÈçÏ£º
hello1.jsp
Int
Ïà¹ØÎĵµ£º
Ò») °²×°JDK(jdk-1_5_0-windows-i586.exe)£¬Ä¬ÈÏ°²×°£»
(¶þ) °²×°Tomcat(tomcat5.5-installer.exe)£¬Ä¬ÈÏ°²×°£»
* ˳Ðò²»¿ÉÒԵߵ¹ *
(Èý) ²âÊÔ°²×°½á¹û
1. ´ò¿ªä¯ÀÀÆ÷ÊäÈëhttp://localhost:8080£¬Èç¹û³É¹¦£¬Ôò»á¿´µ½»¶ÓÒ³Ãæ¡£´Ëʱ·ÃÎʵÄ·¾¶Îª$tomcat/webapps/root/
(ËÄ) ½¨Á¢ÎÒµÄÕ¾µ ......
index.jsp
<%@ page language="java" import="java.sql.*" import="java.lang.*" import="java.util.*" pageEncoding="GB2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%!
& ......
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ʱºòÉ ......
ÔÚ²»ÔÊÐíĿ¼ä¯ÀÀµÄÇé¿öÏ ä¯ÀÀÆ÷»áÏÈÕÒµ½Ê×Ò³£¨Ä¬ÈÏΪindex.html /index.jsp...£©
·ñÔò³ö´í
Òò´Ë ÈôÊ×Ò³±»¶ñÒâ¸ü¸Ä ÍøÕ¾±ÀÀ£
½â¾ö·½·¨£º
¸ü¸ÄĬÈÏÆô¶¯Ò³Ã棺$tomcat/conf/web.xml×îºóλÖÃ
<welcome-file-list>
<welcome-file>index.html</welcome-file> ......
Servlet£º
ÔÚServletÖУ¬ÌøתÔÚdoGet»òÕßdoPost·½·¨ÖÐʵÏÖ¡£
<1>redirectʵÏÖÒ³ÃæÌøת£º
response.sendRedirect("/login.jsp");
·½·¨µÄ²ÎÊýÊÇÏà¶Ô·¾¶£¬É趨Õâ¸ö²ÎÊý¿ÉÒÔʹҳÃæÌøתµ½ÈκÎÒ³Ã棬°üÀ¨www.baidu.comµÈÍøÂçÒ³Ãæ¡£
ÌøתºóÄã¿ÉÒÔ·¢ÏÖµØÖ·À¸·¢ÉúÁ˱仯¡£
µ×²ãÔÀí£ºÊ¹ÓÃredir ......