JSPÌø×ªµÄ¼¸ÖÖ·½Ê½|Struts¶¯Ì¬Ìø×ª
String url="http://www.baidu.com";
ActionForward gotourl = new ActionForward(url);
gotourl.setPath(url);
gotourl.setRedirect(true);
return gotourl;
1.RequestDispatcher.forward()
¡¡¡¡ ÊÇÔÚ·þÎñÆ÷¶ËÆð×÷ÓÃ,µ±Ê¹ÓÃforward()ʱ,Servlet engine´«µÝHTTPÇëÇó´Óµ±Ç°µÄServlet or JSPµ½ÁíÍâÒ»¸öServlet,JSP »òÆÕͨHTMLÎļþ,Ò²¼´ÄãµÄformÌá½»ÖÁa.jsp,ÔÚa.jspÓõ½ÁËforward()ÖØ¶¨ÏòÖÁb.jsp,´ËʱformÌá½»µÄËùÓÐÐÅÏ¢ÔÚ b.jsp¶¼¿ÉÒÔ»ñµÃ,²ÎÊý×Ô¶¯´«µÝ.
¡¡¡¡µ«forward()ÎÞ·¨Öض¨ÏòÖÁÓÐframeµÄjspÎļþ,¿ÉÒÔÖØ¶¨ÏòÖÁÓÐframeµÄhtmlÎļþ,ͬʱforward()ÎÞ·¨ÔÚºóÃæ´ø²ÎÊý´«µÝ,±ÈÈçservlet?name=frank,ÕâÑù²»ÐÐ,¿ÉÒÔ³ÌÐòÄÚͨ¹ýresponse.setAttribute("name",name)À´´«ÖÁÏÂÒ»¸öÒ³Ãæ.
¡¡¡¡Öض¨Ïòºóä¯ÀÀÆ÷µØÖ·À¸URL²»±ä.
¡¡¡¡Àý:ÔÚservletÖнøÐÐÖØ¶¨Ïò
Java´úÂë
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
¡¡ response.setContentType("text/html; charset=gb2312");
¡¡ ServletContext sc = getServletContext();
¡¡ RequestDispatcher rd = null;
¡¡ rd = sc.getRequestDispatcher("/index.jsp"); //¶¨ÏòµÄÒ³Ãæ
¡¡ rd.forward(request, response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
{
¡¡ response.setContentType("text/html; charset=gb2312");
¡¡ ServletContext sc = getServletContext();
¡¡ RequestDispatcher rd = null;
¡¡ rd = sc.getRequestDispatcher("/index.jsp"); //¶¨ÏòµÄÒ³Ãæ
¡¡ rd.forward(request, response);
}
¡¡¡¡Í¨³£ÔÚservletÖÐʹÓ㬲»ÔÚjspÖÐʹÓá£
2.response.sendRedirect()
¡¡¡¡ÊÇÔÚÓû§µÄä¯ÀÀÆ÷¶Ë¹¤×÷,sendRedirect()¿ÉÒÔ´ø²ÎÊý´«µÝ,±ÈÈçservlet?name=frank´«ÖÁϸöÒ³Ãæ,ͬʱËü¿ÉÒÔÖØ¶¨ÏòÖÁ²»Í¬µÄÖ÷»úÉÏ,sendRedirect()¿ÉÒÔÖØ¶¨ÏòÓÐframe.µÄjspÎļþ.
¡¡¡¡Öض¨ÏòºóÔÚä¯ÀÀÆ÷µØ
Ïà¹ØÎĵµ£º
<SCRIPT LANGUAGE="javascript">
//Ö¸¶¨Ò³ÃæÇøÓòÄÚÈݵ¼ÈëWord
function AllAreaWord() {
var oWD = new ActiveXObject("Word.Application");
var oDC = ......
<%@page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="org.springframework.context.ApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="ccp.suddenattack.service.news.*"%>
......
//ѧϰ±Ê¼Ç, ¿ÉÄÜÓÐЩµØ·½Àí½âÓÐÎó, »á±í´ï²»Çå³þ
v512_servlet+jsp
01 ÔÚÐÞ¸ÄÍêCookieºó,Ò»¶¨Òª¼ÓÉÏresponse.addCookie(c);
CookieÖÐÖ»Äܱ£´æ×Öĸ»òÊý×ÖÐÅÏ¢;
02 req.getSession()Óëreq.getSession(boolean create)
ÎÞ²ÎÊýµÄ == ÓвÎÊýµÄ²ÎÊýÎ ......
<body>
<%
Cookie[] cookies = request.getCookies() ;
Cookie cookie = null ;
if(cookies!=null){
cookie = cookies[0] ;
out.print("ÉϴηÃÎʵÄipÊÇ£º " + request.getRemoteAddr() +"<br>") ;&n ......
1 web·þÎñÆ÷{TOMCAT(JSP)¡¢WEBLOGIC(JSP) }
Ó¦Ó÷þÎñÆ÷
We ......