Home > Back-end >  Changes that need to be read request to the servlet request with no response after the excel file, f
Changes that need to be read request to the servlet request with no response after the excel file, f

Time:09-24




Front two excel spreadsheet is directly read, front-end validation normally submit the servlet read write database, followed by a after the discovery of the error is read in excel form validation, open the excel spreadsheet correct mistakes, to read the data uploading front launched a request the request, the back-end servlet no response, is for what is going wrong? If I refresh the page again, be equivalent to each functional module closed set back to the home page and upload to read the file, and then, don't know where the problem is, is part of the front-end back-end code below, please help correct, thank you
 
Js part
//bulk import student information
$(" # import "). Click (function () {
$. Messenger. Confirm (" remind ", "information will be batch import students! Confirm to continue ", function (r) {
If (r) {
$(" # batchImportDialog "). The dialog (" open ");
}
});
});
//batch add student information dialog
$(" # batchImportDialog "). The dialog ({
Title: "bulk import student information,"
Width: 650,
Height: 460,
IconCls: "icon - edit,"
Modal: true,
Collapsible: false,
Minimizable: false,
Maximizable: false,
Draggable: true,
Closed: true,
Buttons: [
{
Text: 'upload file',
Plain: true,
IconCls: 'icon - user_add',
Handler: function () {
/* var validate=$(" # addForm "). The form (" validate ");
if(! Validate) {
$. Messenger. Alert (" remind ", please check your input data! "" , "warning");
return;
} else {
Var gradeid=$(" # add_gradeList "). The combobox (" getValue ");
Var clazzid=$(" # add_clazzList "). The combobox (" getValue "); */
Var form=new FormData (document. GetElementById (" batchImportForm "));
$. Ajax ({
Type: "post",
Url: "StudentServlet? Method=BatchImportStudent& T="+ new Date (). GetTime (),
Data: the form,
ProcessData: false,
ContentType: false,
Success: the function (MSG) {
{if (MSG=="success")
$. Messenger. Alert (" remind ", "information batch import students success", "info");
//to refresh the form
$(" # dataList "). The datagrid (" reload ");
$(" # dataList "). The datagrid (" uncheckAll ");
} else {
$. Messenger. Alert (" remind ", MSG, "warning");
return;
}
}
});
}
},
]
});

$(' # fb) filebox ({
ButtonText: 'select files,
ButtonAlign: 'right',
Accept: application/VND. - ms excel,
});
HTML part


 
The back-end code section
//read excel spreadsheet information, bulk import database
Private void batchImportStudent (it request, HttpServletResponse response) {
response.setContentType("text/html; Charset=utf-8 ");
System. The out. Println (" batch upload button ");
Try {
//import database header template
String [] databaseTitleTemp={" number ", "name", "sex", "phone", "qq", "clazzid", "gradeid"};
String [] titleNameList=new String [databaseTitleTemp length].
Object [] gradeclazzid=null;
//create factory
DiskFileItemFactory factory=new DiskFileItemFactory ();
String path=this. GetServletContext (.) getRealPath ("/upload ");
The File f=new File (path);
if(! F.e xists ()) {
f.mkdirs();
}
//Settings file cache path
Factory. SetRepository (f);
//create the fileupload component
ServletFileUpload fileupload=new ServletFileUpload (factory);
Fileupload. SetHeaderEncoding (" GBK ");
//parse request
List Fileitems=fileupload. ParseRequest (request);
PrintWriter writer.=the response getWriter ();
//traverse collection
First: the for (FileItem FileItem: fileitems) {
//determine whether for ordinary field
If (fileitem isFormField ()) {
//get the field name and field value
String name=fileitem. GetFieldName ();
String value=https://bbs.csdn.net/topics/fileitem.getString (" GBK ");
} else {
//upload file path
The String filename=fileitem. GetName ();
//subtracted filename
Filename=filename. The substring (filename. LastIndexOf (" \ \ ") + 1);
//file name needs to be the only
Filename=UUID. RandomUUID (). The toString () + "_" + filename;
//a file on the server to create
String webPath="/upload/";
String filepath=getServletContext (.) getRealPath (webPath + filename);
//create a file
The File File=new File (filepath);
file.getParentFile().mkdirs();
file.createNewFile();
//get uploaded file stream
InputStream in=fileitem. GetInputStream ();
HSSFSheet sheet=bimportStudent. GetSheet (in);
//get form total number of rows
Int rows=bimportStudent. GetTotalRows (sheet);
//obtained form the total number of columns
Int columns=bimportStudent. GetTotalColumns (sheet);
First line//upload form template
String [] titleNameTemp={" student id ", "name", "gender", "phone", "QQ", "class", "grade"};
ExcelDataValidate ExcelDataValidate=new ExcelDataValidate ();
//contrast and upload form template first line are consistent
String validateTitleInfo=excelDataValidate. TitleNameCompare (titleNameTemp bimportStudent, sheet);
if(! ValidateTitleInfo. Equals (" true ")) {
Writer. Print (validateTitleInfo);
ValidateTitleInfo=null;
in.close();
Break first.
} else {
for(int i=0; ITitleNameList [I]=databaseTitleTemp [I];
}
}
//data validity check upload form
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related