如何使用ExtJs将参数发送到服务器
How to send parametrs to server with ExtJs?
我将文件上传到服务器并发送参数。但我有两个问题。
1无法发送参数。我知道:
handler: function(){
mapinfo="mapinfo";
formp.getForm().submit({
url: url_servlet+'uploadfile',
params: {file_type: mapinfo},
success: function(formp, o) {
alert(o.result.file);
kad_tab.getStore().reload()
zoom_store.load();
}
})
}
服务器端:
public class uploadfile extends HttpServlet implements Servlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
String st = request.getParameter("file_type");
PrintWriter writer = response.getWriter();
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
return;
}
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List<FileItem> list=null;
String mifpath= "1";
String path = " ";
String mif = " ";
String from = "''''";
String to ="/";
String error="";
try{
list = upload.parseRequest(request);
Iterator<FileItem> it = list.iterator();
response.setContentType("text/html");
while ( it.hasNext() )
{
FileItem item = (FileItem) it.next();
File disk = new File("C:/uploaded_files/"+item.getName());
path = disk.toString();
String code = new String(path.substring(path.lastIndexOf("."), path.length()).getBytes("ISO-8859-1"),"utf-8");
if (code.equalsIgnoreCase(".zip"))
{
mifpath=path;
mif = mifpath.replaceAll(from, to);
item.write(disk);
//error=unzip.unpack(mif, "C:/uploaded_files");
}
else
{
error = "Выбранный файл не является архивом zip";
}
}
}
catch ( Exception e ) {
log( "Upload Error" , e);
}
System.out.println("st="+st);
writer.println("{success:true, file:'"+error+"'}");
writer.close();
}
}
但在控制台中只能得到st=null
。
2不能在文件上传面板中使用组合框:
var x = new Ext.Window({
title:'Загрузка файла',
items:[
formp = new Ext.FormPanel({
fileUpload: true,
width: 350,
autoHeight: true,
bodyStyle: 'padding: 10px 10px 10px 10px;',
labelWidth: 70,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items:[{
xtype:"combo",
fieldLabel:'Тип файла ',
name:"cb_file",
id:"cb_file",
mode:"local",
typeAhead: false,
loadingText: 'Загрузка...',
store:new Ext.data.SimpleStore({
fields: ['file_name', 'file_type'],
data : [['*.MIF/MID', 'mif'],['*.GPX', 'gpx']]
}),
forceSelection:true,
emptyText:'выбирите тип...',
triggerAction:'all',
valueField:'file_type',
displayField:'file_name',
anchor:'60%'
},{
xtype: 'fileuploadfield',
id: 'filedata',
emptyText: 'Выберите файл для загрузки...',
fieldLabel: 'Имя файла',
buttonText: 'Обзор'
}],
buttons: [{
text: 'Загрузить',
handler: function(){
mapinfo="mapinfo";
formp.getForm().submit({
url: url_servlet+'uploadfile',
params: {file_type: mapinfo},
success: function(formp, o) {
alert(o.result.file);
kad_tab.getStore().reload()
zoom_store.load();
}
})
}
}]
})
]
})
x.show();
如果我在服务器端这样做,什么都不起作用。例如,如果我上传的不是zip档案,我会收到一个警告,上面写着它不是zip文件,但没有得到它。如果我没有在面板上添加组合框,我会得到这个警告。怎么了?
这是因为请求是一个多部分的请求。然后,您无法使用以下方法读取参数:String st=request.getParameter("file_type");
因为它将永远为空。相反,使用以下狙击手:
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
processFormField(item);
} else {
processUploadedFile(item);
}
}
关于你的第二个问题,我无法理解。
相关文章:
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 使用useMasterKey参数分析每个服务器查询
- 使用新参数通过服务器端处理重新绘制引导数据表
- 如何使用ExtJs将参数发送到服务器
- Ajax's的数据参数未发送到服务器
- 服务器不读取科尔多瓦文件传输选项参数
- 从插件向Datatables添加额外的服务器参数
- 添加其他参数以使用fin上传器发送到服务器
- 无法使用angularjs$http请求将参数发送到服务器操作方法
- 将jQuery参数发送到服务器端并创建输出文本文件
- 将参数传递到JavaScript的安全方式,无需服务器端脚本
- 数据表1.8.0添加服务器参数无效
- 覆盖 JQGrid 参数在服务器端找到
- 如何通过角度服务器路由发送 Ajax 参数
- 当我尝试在 couchbase nodejs 服务器上运行简单的测试时,我收到“不正确的参数”错误
- 将参数从网页传递到服务器(烧瓶)
- 如何使用 ajax 调用带有参数(对象)的服务器端方法,其中 url 具有查询参数
- React 服务器端渲染 - 如何使用传入的 :p roductId 参数从服务器渲染
- Java 服务器页面.如何将参数从一个 JSP 页发送到另一个 JSP 页
- 数据表服务器端添加带参数的列