ÔÚWEBÓ¦ÓÃÖÐ,Èç¹ûʹÓÃjsp×÷Ϊview²ãµÄÏÔʾģ°å,¶¼»á±»¿Õ¸ñ/¿Õ»»ÐÐÎÊÌâËùÀ§ÈÅ.
Õâ¸öÎÊÌâµ±ÄêÒ²À§ÈÅÁËÎұȽϳ¤µÄʱ¼ä.ÒòΪÔÚjspÄÚʹÓõÄEL±êÇ©ºÍÆäËû±êǩʱ,»á²úÉú´óÁ¿µÄ¿Õ¸ñºÍ»»Ðзû.ÀýÈç:
------- start ----------
<c:choose>
<c:when test="${fn:length(mainPageList)>1&}">
Something
</c:when>
<c:otherwise>
Others
</c:otherwise>
</c:choose>
------- end -----------
Õâ¶Î´úÂëÔÚTomcatÉÏÊä³öÈçÏ£¬¶àÁ˼¸Ðл»ÐС£
------- start ----------
Something
------- end -----------
µ±È»£¬Ò»°ã²»È¥ÌرðÁôÒâÊDz»»á·¢ÏÖÓÐʲôÎÊÌâµÄ£¬±Ï¾¹Êä³öÔÙ¶àµÄ¿Õ¸ñºÍ»»Ðзû£¬¶ÔÓÚä¯ÀÀÆ÷Éú³ÉµÄ×îÖÕЧ¹ûÊÇÒ»ÑùµÄ¡£Ò²¾ÍÊǴ󲿷ֿª·¢ÈËÔ±ºöÂÔÕâ¸öÎÊÌâµÄÔÒò£»µ«Êµ¼ÊÉÏÕâЩ¿Õ¸ñºÍ»»ÐлáÕ¼ÓÃÁ˲»Éٿռ䣬ÎҵľÑéÊÇ30%×óÓÒÊǿոñ/»»ÐС£Ò²ÓÐÈË˵£¬µ±web·þÎñÆ÷ÒÔzipµÄ·½Ê½À´Êä³öhtmlʱ£¬¿Õ¸ñÒýÆðµÄ´ø¿íÎ ......
Ïàͬµã£º
Èç¹û±»°üº¬½øÈ¥µÄÎļþÀïÃæÓÐcssÎļþµÄ»°£¬°üº¬µÄÒ³Ãæ»áÊܵ½±»°üº¬ÎļþµÄcssÑùʽµÄÓ°Ï죡
²»Í¬µã£º
<%@ include
file="date.jsp" %>
<jsp:include
page="date.jsp" flush="true"/>
include
±àÒëÖ¸ÁîÊÇÔÚ
JSP
³ÌÐòµÄת»»Ê±ÆÚ¾Í½«
file
ÊôÐÔËùÖ¸¶¨µÄ³ÌÐòÄÚÈÝǶÈ룬ȻºóÔÙ±àÒëÖ´ÐУ»
»¹ÓоÍÊÇÈç¹û°üº¬.jspµÄÎļþµÄ»°£¬¾³£Â·¾¶»á³öÏÖÎÊÌâ¡£
¶ø
include
Ö¸ÁîÔÚת»»Ê±ÆÚÊDz»»á±»±àÒëµÄ£¬Ö»ÓÐÔÚ¿Í»§¶ËÇëÇóʱÆÚÈç¹û±»Ö´Ðе½²Å»á±»¶¯Ì¬µÄ±àÒëÔØÈë
Ö»Éú³ÉÒ»¸ö
class
Îļþ
¶à¸ö
Include
²»ÄÜ´ø²ÎÊý
<jsp:include>
¿ÉÒÔ
ͬһ¸ö
request
¶ÔÏó
²»Í¬µÄ
request
¶ÔÏ󣬿ÉÒÔÈ¡µÃ°üº¬ËüµÄÒ³ÃæµÄ²ÎÊý£¬²¢Ìí¼ÓÁË×Ô¼ºµÄ²ÎÊý
³£ÓÃ
²»³£ÓÃ
......
JSPÎļþÏÂÔØ-----------------------------------------------------------------
<%@ page contentType="text/html; charset=GBK"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="java.io.File"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.FileInputStream"%>
<%
String path = request.getParameter("path") ;
if(path==null || "".equals(path)){
out.write("<mce:script type="text/javascript"><!--
") ;
out.write("alert('ÒªÏÂÔØµÄÎļþ²»´æÔÚ');") ;
out.write("history.go(-1);") ;
out.write("
// --></mce:script>") ;
}
String realPath = "c:/myfile/ÕýÎÄ.doc" ;
File file = new File(realPath) ;
if(!file.exists()){
out.write("<mce:script type="text/javascript"><!--
") ;
out.write("alert('ÒªÏÂÔØµÄÎļþ²»´æÔÚ');") ;
out.write("history.go(-1);") ;
out.write("
// --></mce:script>") ;
......
ÔÚʹÓÃÁ÷µÄ·½Ê½½øÐÐÏÂÔØÎļþʱ»á³öÏÖ³£¼ûµÄÁ½ÖÖÏÖÏó£º
1¡¢llegalStateException:getOutputStream() has already been called
2¡¢ClientAbortException: java.net.SocketException
²úÉúÎÊÌâµÄÔÒòÕýÈçºÜ¶à¸ßÊÖËù˵һÑù£ºout.printºÍoutputstreamÖ®¼äµÄ³åÍ»»òÊÇ<%%>Ö®ÍâÓÐHTML´úÂë»ò¿ÕÐУ¬´¦Àí·½Ê½½¨ÒéÊÇÌí¼ÓÏÂÃæÁ½ÐоͿÉÒÔÁË:
out.clear():
out=pageContext.pushBody();
ÎÒÒ²×öÁ˳¢ÊÔ£¬½á¹ûÊÇÓÉÏÖÏó1±ä³ÉÏÖÏó2¡£
¼ÈÈ»³åÍ»¾ÍÒ»¿ªÊ¼¾Í¹Øµôout£¬È»ºó´¦Àí£¬Õý³£ÏÂÔØÃ»ÓÐÎÊÌ⣬ȡÏûÏÂÔØÊ±»¹ÊdzöÏÖÎÊÌâ2
response.reset();
response.setContentType("application/x-download");
String path=request.getParameter("path");
URL url=new URL(path);
String filenamedisplay = new File(path).getName();
filenamedisplay = URLEncoder.encode(filenamedisplay, "GBK");
response.addHeader("Content-Disposition", "attachment;filename="+ filenamedi ......
´íÎó£º
String realPath = " http:// " + request.getServerName() + " : " + request.getServerPort() + request.getContextPath();
String realPath = " http:// " + request.getServerName() + " : " + request.getServerPort() + request.getServletPath();
ÕýÈ·£º
String realPath = " http:// " + request.getServerName() + " : " + request.getServerPort() + request.getContextPath() + request.getServletPath().substring( 0 ,request.getServletPath().lastIndexOf( " / " ) + 1 );
Èç¹ûÏëÁ¬´ø»ñÈ¡Ò³ÃæµÄÃû³ÆÊ±ÔòÈ¥µô×îºóµÄsubstring¼´¿É. ......
Ϊ¹«Ë¾ÄÚ²¿¿ª·¢ÁË1¸ö¼òµ¥µÄMVC¿ò¼Ü£¬¿ò¼ÜÖÐÐèÒªÏòËùÓÐJSPÒ³ÃæµÄ<head>ÖвåÈë2ÌõÒýÓÃJSµÄ´úÂ룬ʵÏÖÈçÏ£º
Ö÷ÒªÊǼ̳ÐHttpServletResponseWrapperд1¸öÀà(PageResponseWrapper),´úÂ룺
1 public class PageResponseWrapper extends HttpServletResponseWrapper {
2 private Buffer buffer;
3 private HttpServletResponse originalResponse;
4
5 public PageResponseWrapper(final HttpServletResponse response){
6 super(response);
7 this.originalResponse = response;
8 buffer = new Buffer();
9 }
10
11 @Override
12 public&nbs ......