jspÏÂÔØÒì³£´¦Àí
ÔÚʹÓÃÁ÷µÄ·½Ê½½øÐÐÏÂÔØÎļþʱ»á³öÏÖ³£¼ûµÄÁ½ÖÖÏÖÏó£º
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="+ filenamedisplay);
OutputStream output = null;
InputStream is = null;
try {
out.clear();
output = response.getOutputStream();
URLConnection urlConn = url.openConnection();
is = urlConn.getInputStream();
byte[] b = new byte[1024*10];
int i = 0;
while ((i = is.read(b))> 0) {
output.write(b,0, i);
}
output.flush();
output.colse();
...
...
&n
Ïà¹ØÎĵµ£º
ÔÚÏîÄ¿ÖУ¬ÎÒÃǾ³£Óöµ½ÐèÒªÔÚjspÒ³ÃæÇл»Öд«µÝÖÐÎÄ×Ö·û¡£ÕâÖ÷ÒªÓÐÁ½ÖÖ·½Ê½¡£
¡¡¡¡URL·½Ê½£¬ÀýÈ磺http://website/test1.jsp?act=add&type=Æ»¹û¶m=%20D%20B
¡¡¡¡FORM·½Ê½£¬ÀýÈ磺
¡¡¡¡<form name=test mehtod="post">
¡¡¡¡<input type=hidden name=text2 value="ÖÐÎÄ">
¡¡¡¡<input type=t ......
ÔÚjspÖв»Óö¨Òå¿ÉÒÔÖ±½ÓÓõľÍÊÇjspµÄ9¸öÄÚ½¨¶ÔÏóÁË
1£¬Request 2,Response 3,session 4,out 5,page
6,application 7,pageContext 8,config
9,exception
1¡¢Request¶ÔÏó
¸Ã¶ÔÏó·â×°ÁËÓû§Ìá½»µÄÐÅÏ¢£¬Í¨¹ýµ÷ÓøöÔÏóÏàÓ¦µÄ·½·¨¿ÉÒÔ»ñÈ¡·â×°µÄÐÅÏ¢£¬¼´Ê¹ÓøöÔÏó¿ÉÒÔ
»ñÈ¡Óû§Ìá½»µÄÐÅÏ¢¡£
µ±Request¶ÔÏó»ñÈ¡¿Í» ......
Ö»Ðè´ÓÊý¾Ý¿â²é³öÀ´ºóÔÚÏÔʾµÄµØ·½ÓÃ<pre></pre>±êÇ©ÐÞÊΣ¬ÈçÏ£º
<!--
<div style="font-size:12px;color:green;text-align:left">
<pre>
<%=
&n ......
ÕÒÏÂÃæÐ´·¨¡£
×¢Ò⣬¼Óµ¥ÒýºÅ£¬µÚ2¸ö°Ù·ÖºÅ֮ǰûÓпոñ£¬¶øÔÚjspÖе÷ÓõĻ°Òª¿Õ¸ñ¡£
You may be get some help from the code below.
<%
String str="str";
%>
<script>
function accessVar(){
var varStr='<%=str%>';
alert(varStr);// here will diplay ......
JSPÖÐfilter¹ýÂËÆ÷ÑéÖ¤Óû§µÇ¼
ÏÖÔÚJSPʹÓÃÔ½À´Ô½¹ã·ºÁË£¬ÓÈÆäÊǺܶàÕþ¸®µÄÍøÕ¾¶¼²ÉÓÃÁËJSP¼¼Êõ£¬Æä¹¦ÄÜÇ¿´óÇÒ°²È«¡£
³õѧÕߺܶàÓÐÕâô¸öÎÊÌ⣬¾ÍÊÇ£¬ÍøÕ¾µÄÒ»¸öȨÏÞÉèÖ㬱ÈÈçµÇ¼Óû§¿ÉÒԲ鿴ÄÄÐ©Ò³Ãæ£¬¶øÓοÍÓÖÓÐȨÏÞ¿ÉÒÔ¿´ÄÄЩÄÚÈÝÄØ£¿
JSPÊÇÇ¿´óµÄ£¬µ«Æä´úÂ뻹ÊÇÏà¶Ô·±ËöµÄ£¬ÆäʵÓÃÒ»¸ö¹ýÂËÆ÷(filter)¾Í¿ÉÒÔʵÏÖÕ ......