简体   繁体   English

从一个jsp页面到另一个jsp页面的表单数据文件上传

[英]File Uploading with form data from one jsp page to another jsp page

I have two jsp page, in first page i write html code. 我有两个jsp页面,在第一页中,我编写html代码。 in html i have on form in which two textbox and one file upload control and submit button. 在HTML中,我有两个文本框和一个文件上载控件和提交按钮的形式。

now, when i click on submit button then i want to get whole form data (textbox data and file path) in second jsp page. 现在,当我单击提交按钮时,我想在第二个jsp页面中获取整个表单数据(文本框数据和文件路径)。

In second jsp page i write code of file uploading. 在第二个jsp页面中,我编写了文件上传代码。

My problem is i didn't get both data in second jsp page. 我的问题是我没有在第二个jsp页面中同时获得两个数据。 i got either textbox data or file. 我得到了文本框数据或文件。 but i want both at a time. 但我一次都想要。

so please help me. 所以请帮我 Thanks. 谢谢。



Suppose you Defined myFile name as a private and apply setter and getter method on variable. 假设您将myFile名称定义为私有,并在变量上应用了setter和getter方法。 that will give you a file name what ever you have upload it from upload control . 它将为您提供一个文件名,无论您从上传控件上传到什么文件。

  • use taglib for get property Name in JSP Code . 使用taglib在JSP Code中获取属性Name。

     private File myFile; //give file name private String TextValue; // give text field value public File getMyFile() { return myFile; } public void setMyFile(File myFile) { this.myFile = myFile; } public String getTextValue() { return TextValuee; } public void setTextValue(String TextValue) { this.TextValue = TextValue; } 

then go JSP and Define taglib and value using property Name Code :- 然后去JSP并使用属性名称代码定义taglib和值:-

 <%@ page contentType="text/html; charset=UTF-8" %>
 <%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>File Upload Success</title>
</head>
<body>
You have successfully uploaded <s:property value="<s:property value="Myfile"/>"/>
with TextBox <s:property value="<s:property value="TextValue"/>"/>
</body>
</html>

try like this 这样尝试

first.jsp first.jsp

<form action='secondjsp.jsp' method='post' enctype='multipart/form-data'>
<input type='textbox' name="textbox"/>
<input type='submit' value='submit' />
</form>

second.jsp second.jsp

<%
String file = request.getParameter('textbox');
%>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM