ajax如何获取对象,如何在ajax之后获取新的请求对象

我正在使用JSP和SERVLET开发WEB PROJECT。如何在ajax之后获取新的请求对象

我想上传使用AJAX调用的文件。 文件已成功上传。 但是,虽然ajax称为控制器(servlet文件)向jsp文件发送请求和响应对象。

JSP文件

$(document).ready(function(){

$(':file').change(function(){

var fileObj = this.files[0];

var form = $('#mOBJ');

var fd = new FormData();

fd.append('file', fileObj);

$.ajax({

url:form.attr('action'),

type:form.attr('method'),

data:fd,

processData: false,

contentType: false,

async:false,

}).done(function(){

alert('ajax complete');

/ /// 在这里,我收到了旧的请求值。 我希望在调用ajax之后获得新的请求和响应对象。

var Check2Bool = ;

var check2 = ;

alert(Check2Bool + " " + check2);

}).fail(function() {

alert("error");

$('#ldiv').hide();

});

});

的Servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

ServletContext context = getServletContext();

/**

* Display XML file to the user

*/

TemplateVO template = null;

TemplateUtil util = new TemplateUtil();

//Prepare XML file path

String path=(String) context.getAttribute(Constants.USER_DIR);

String strFilePath = null;

//Upload XML file

if(ServletFileUpload.isMultipartContent(request)){

try{

List multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);

for(FileItem item : multiparts){

if(!item.isFormField()){

String name = new File(item.getName()).getName();

request.setAttribute("FileName",name);

String path1 = path + File.separator + "data-in";

strFilePath = FileUtil.createFileOnFileSystem(item,path1,name,"xml");

}

}

}catch(Exception ex){

ex.printStackTrace();

}

}

//set variables into Request Object

template = util.readXML(strFilePath);

context.setAttribute("comeFromUploadTemp", true);

request.setAttribute("comeFromUploadTemp", true);

request.getRequestDispatcher("mappingObject.jsp").forward(request, response);

}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

doGet(request, response);

}

2014-10-11

Chintan

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值