我有两个jsp页面,在第一页我写了html代码。在html中我有一个表单,其中两个文本框和一个文件上传控件和提交按钮。
现在,当我点击提交按钮然后我想在第二个jsp页面中获取整个表单数据(文本框数据和文件路径)。
在第二个jsp页面中,我编写了文件上传代码。
我的问题是我没有在第二个jsp页面中获取这两个数据。我有文本框数据或文件。但我一次都想要两个。
所以请帮助我。 感谢。
答案 0 :(得分:0)
假设您将myFile名称定义为私有,并对变量应用setter和getter方法。这将为您提供一个文件名,您可以从上传控件上传它。
在JSP代码中使用taglib获取属性名称。
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并使用属性Name Code定义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>
答案 1 :(得分:0)
试试这个
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');
%>