When you encounter a form that has both a file upload and a Received field, the field wants to be request.getparameter, often null.
<form action= "FileUpload" method= "post" enctype= "Multipart/form-data" Name= "Form1" >
<input type= "text" Name= "text" >
<input type= "file" name= "file" >
<input type= "button" Name= "Submit" value= "Upload" Onclick= "OK ()" >
</form>
As above, call Request.getparameter ("text") in the public void DoPost (HttpServletRequest request, httpservletresponse response) To get a null
How to get it. There are two kinds of solutions
1, with two forms: (More trouble)
A from that uses a file submitted by post to upload from, a field that takes a get commit, and then the value of the second form as the first argument
function ok () {
var name = Form2.name.value;
var title= form2.title.value;
form1.action= "Fileupload?name=" +name+ "&title=" +title;
Form1.submit ();
}
2,commons-fileupload Judge FieldName, to distinguish whether the file is uploaded or field
Servletfileupload upload = new Servletfileupload (factory);
try {
List items = upload.parserequest (request);
for (Iterator i = Items.iterator (); I.hasnext ();) {
Fileitem Fileitem = (fileitem) i.next ();
String field = Fileitem.getfieldname (); Judge FieldName,
if (field.equals ("kind")) {
kind = fileitem.getstring ();
Continue;
} else if (field.equals ("id")) {
id = fileitem.getstring ();
Continue;
} else if (field.equals ("topic")) {
topic = fileitem.getstring ();
Continue
3, JSP
SmartuploadSpecifically provided Smartupload.getrequest (). GetParameter ("text")
A specific introduction to see me another blog http://blog.csdn.net/jazywoo123/article/details/7900114