Se puede utilizar directamente
jquery obtiene la ruta completa de carga de archivos. Da el código completo.
Se puede utilizar directamente
1 Primero es jsp
2. Luego js
$(function(){
var uploadCom = null;
function uploadIt() {
$("#importWhiteBtn").click(function() {
var uploadId = " #" + $(this).attr("id");
var btn = $(this);
uploadCom = new AjaxUpload( uploadId + "" , {< / p>
acción: "whitePhoneNumber.do?action=importFile",
onSubmit: función(archivo, text) {
if ((ext && /^(txt) $/.test(ext))) {
alert("Primero descargue la plantilla de importación readme.txt como referencia. El formato del documento que cargó es incorrecto, selecciónelo nuevamente!"); /p>
return false;
}
$.blockUI({
mensaje: "Subiendo al servidor...."
})
},
onComplete: función(archivo, respuesta) {
$.unblockUI(); > if( respuesta=="éxito"){
alerta( "Importación exitosa");
$('#whitePhoneList').flexReload();
} else{
alerta( "Error de importación",+respuesta
}
}
});
});
$(".uploadAndNext").click();
}
uploadIt()
;
firstClick = false;
})
3. Finalmente, acción
importFile público ActionForward (mapeo de ActionMapping, formulario ActionForm,
Solicitud HttpServletRequest, respuesta HttpServletResponse) arroja una excepción{
FileItemFactory factory = new DiskFileItemFactory();
Carga de ServletFileUpload = new ServletFileUpload(factory
Cadena de éxito = "éxito";
BufferedReader br=null;
InputStream in=null;
Operador de cadena = UserNameUtil.getUserName(solicitud) );
String areaCode = whitePhoneManager.getAreaCodeByOperator(operator);
prueba {
List for (int i = 0; i < list.size(); i++) { FileItem fileItem = list.get(i); String nombre = fileItem.getName().substring( fileItem.getName().lastIndexOf("\\") + 1 if(fileItem.getSize() > 2097152); ){ //200k throw new Exception("El tamaño del archivo excede los 2M"); } log.debug("cargar nombre de archivo:" + nombre) in= fileItem.getInputStream(); br = new BufferedReader(new InputStreamReader(in)); whitePhoneManager.processFile(br, areaCode) ; logutil.log_Operation(solicitud, LogUtil.LOG_MODULE_SYSTEMCONFIG, LogUtil.LOG_EVENT_CREATE, "Lista blanca de SMS de importación por lotes", "nombre de archivo: " + nombre, "Éxito", LogUtil.SUCCESS); } } captura (FileUploadException e) { log.debug ( "error", e); éxito =e.getMessage() ; } catch (Excepción e) { log.debug("error", e); éxito=e. getMessage() ; }finalmente{ if(br!=null) try{br.close();}catch(Exception e){log.error("no se puede close bufferdreader",e);} if(in!=null) try{in.close();}catch(Exception e){log.error("no se puede cerrar el flujo de entrada",e) ;} respuesta.setContentType("text/html"); respuesta.setCharacterEncoding("UTF-8"); respuesta.getWriter(); .write(éxito); devuelve nulo; } }