JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 POST傳遞參數問題
jouabcd





發文: 8
積分: 0
於 2011-06-20 20:21 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以下我部分程式碼

我從另一個程式接收POST,然後又要把它POST到另一個程式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%
String path = request.getParameter("path");
%>
 
<html>
  <head>
    <title></title>
  </head>
  <body>
  <form action="usingsmartupload.jsp"  enctype="multipart/form-data" name=theFile  method="post" > 
      <input type="hidden" name="path" value="<%=path%>"> 
      <input type=file name=File1 size=50 /> <br>
       
      <input type=submit name=submitButton value="上傳"   />   
  </form>
  </body>
</html>


我把path POST到usingsmartupload.jsp

然後再usingsmartupload.jsp接收POST 可是就是收不到path

是哪裡出現問題嗎???


reply to postreply to post
作者 Re:POST傳遞參數問題 [Re:jouabcd]
crow1111





發文: 37
積分: 0
於 2011-06-20 22:25 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Hi:
我覺得最好先確認,request.getParameter("path");確實有值

您可以這樣:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%
String path = request.getParameter("path")!=null?(String)request.getParameter("path"):"";
out.print(path);//Debug用
%>
 
<html>
  <head>
    <title></title>
  </head>
  <body>
  <form action="usingsmartupload.jsp"  enctype="multipart/form-data" name=theFile  method="post" > 
      11111111111:<%= path %><!--Debug用-->
      <input type="hidden" name="path" value="<%=path%>"> 
      <input type=file name=File1 size=50 /> <br>
       
     
      <!--<input type=submit name=submitButton value="上傳"   />-->
      <!--我覺得應該要改成以下-->
       <input type='submit' name='submitButton' value='上傳' onclick="javascript:theFile.submit();"   />   
  </form>
  </body>
</html>
 
 
 


crow1111 edited on 2011-06-20 22:27
reply to postreply to post
Shadow與愉快的程式碼伙伴
自Hight文不定期更新中XD
作者 Re:POST傳遞參數問題 [Re:jouabcd]
mildseven





發文: 37
積分: 0
於 2011-06-21 00:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
jouabcd wrote:
以下我部分程式碼

我從另一個程式接收POST,然後又要把它POST到另一個程式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<%
String path = request.getParameter("path");
%>
 
<html>
  <head>
    <title></title>
  </head>
  <body>
  <form action="usingsmartupload.jsp"  enctype="multipart/form-data" name=theFile  method="post" > 
      <input type="hidden" name="path" value="<%=path%>"> 
      <input type=file name=File1 size=50 /> <br>
       
      <input type=submit name=submitButton value="上傳"   />   
  </form>
  </body>
</html>


我把path POST到usingsmartupload.jsp

然後再usingsmartupload.jsp接收POST 可是就是收不到path

是哪裡出現問題嗎???


因為加了這個 enctype="multipart/form-data"
所以沒辦法取得~


reply to postreply to post
作者 Re:POST傳遞參數問題 [Re:mildseven]
jouabcd





發文: 8
積分: 0
於 2011-06-21 08:34 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問

有辦法讓他取得嗎??


reply to postreply to post
作者 Re:POST傳遞參數問題 [Re:jouabcd]
jeson001





發文: 29
積分: 0
於 2011-06-21 09:06 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
因為enctype="multipart/form-data"是上傳使用,此時其他欄位會抓不到
想要同時上傳和抓欄位資料有幾種方法
1.
1
2
3
var path = document.getElementById("path").value;
document.theFile.action="./usingsmartupload.jsp?path="+path;
document.theFile.submit();

這樣可以同時上傳並抓到欄位值,不過缺點是欄位很多時url要寫很長

2.使用jQuerry,他有很多套件
我自己使用uploadify它可以無刷新上傳,就是他先上傳後你在action到抓欄位頁面

3.上傳頁面和資料頁面分離,如果可以的話

自己寫過的心得,不才分享,如有錯誤,敬請指教


reply to postreply to post
作者 Re:POST傳遞參數問題 [Re:jeson001]
roytsang





發文: 620
積分: 1
於 2011-06-21 09:18 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
正如mildseven大所講,因為有了enctype="multipart/form-data",所以用request.getParameter是讀不到value 的,建議你使用以下lib:

http://commons.apache.org/fileupload/index.html

至於如何使用,你可以上網google 一下

或者你可以試用我的attachment.

hellofileupload10.zip (58.17k)


roytsang edited on 2011-06-21 09:32
reply to postreply to post
作者 Re:POST傳遞參數問題 [Re:jouabcd]
bernardvai





發文: 491
積分: 0
於 2011-06-21 10:12 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如你是用 smartUpload .

可試試將以下這行
String path = request.getParameter("path");

改為.

String path = mySmartUpload.getRequest().getParameter("path");

===============================================
mySmartUpload 是你的 SmartUpload Object 的名.
com.jspsmart.upload.SmartUpload mySmartUpload = new com.jspsmart.upload.SmartUpload();


reply to postreply to post
作者 Re:POST傳遞參數問題 [Re:jouabcd]
uuuiii00





發文: 5
積分: 0
於 2014-12-19 20:02 user profilesend a private message to usersend email to uuuiii00reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
http://www.andowson.com/posts/list/197.page
參考這篇文章看看
我是可以成功執行
抓到檔案及欄位資料


reply to postreply to post
» JWorld@TW »  Servlet/JSP 討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8