[英]File Uploading with form data from one jsp page to another jsp page
我有两个jsp页面,在第一页中,我编写html代码。 在HTML中,我有两个文本框和一个文件上载控件和提交按钮的形式。
现在,当我单击提交按钮时,我想在第二个jsp页面中获取整个表单数据(文本框数据和文件路径)。
在第二个jsp页面中,我编写了文件上传代码。
我的问题是我没有在第二个jsp页面中同时获得两个数据。 我得到了文本框数据或文件。 但我一次都想要。
所以请帮我 谢谢。
假设您将myFile名称定义为私有,并在变量上应用了setter和getter方法。 它将为您提供一个文件名,无论您从上传控件上传到什么文件。
使用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; }
然后去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>
这样尝试
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
<%
String file = request.getParameter('textbox');
%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.