我刚刚安装了 GWT 2.6,现在收到错误“描述资源路径位置类型文件 war\WEB-INF\lib\gwt-servlet.jar 的大小与 GWT SDK 库 gwt-servlet.jar 不同;也许是不同的版本?gwt-servlet.jar /AwardTracker/war/WEB-INF/lib Unknown Google Web Toolkit Problem"
我下载了 GWT 2.6 zip,然后将目录“GWT-2.6.0”复制到“Eclipse\eclipse-jee-juno-SR1-win32\eclipse\plugins”中。然后我右键单击该项目并选择“properties/Google/Web Toolkit/Configure SDKs.../Add”。然后我浏览到“GWT-2.6.0”目录,添加并选择它。
我遵循了 Braj 的解决方案,并在重新编译时收到以下错误:
编译模块 org.AwardTracker.AwardTracker 验证单元:在第一次通过时忽略 2 个编译错误的单元。编译时使用 -strict 或将 -logLevel 设置为 TRACE 或 DEBUG 以查看所有错误。计算 'gwtupload.client.DecoratedFileUpload.DecoratedFileUploadImpl' 的所有可能的重新绑定结果 重新绑定 gwtupload.client.DecoratedFileUpload.DecoratedFileUploadImpl 找不到完全匹配的规则。使用基于回退值的“最近”规则。您可能需要实现特定的绑定,以防回退行为无法替换缺少的绑定' 不能是抽象的
通过下载 gwtupload-1.0.1.jar,使用“添加外部 JARS”将其添加到库并删除旧的 gwtupload-0.6.6.jar 来修复上述问题。然后我重新编译并编译工作。但是,现在我的“MyCustomisedUploadServlet”中有一个错误(这个错误以前不存在):
protected static final String XML_ERROR_ITEM_NOT_FOUND = "<" + TAG_ERROR + ">item not found</" + TAG_ERROR + ">";
其余的代码是:
package org.AwardTracker.server;
import gwtupload.server.UploadAction;
import gwtupload.server.exceptions.UploadActionException;
import gwtupload.shared.UConsts;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
/**
* This is an example of how to use UploadAction class.
*
* This servlet saves all received files in a temporary folder,
* and deletes them when the user sends a remove request.
*
* @author Manolo Carrasco Moñino
*
*/
public class MyCustomisedUploadServlet extends UploadAction {
private static final long serialVersionUID = 1L;
protected static final String XML_ERROR_ITEM_NOT_FOUND = "<" + TAG_ERROR + ">item not found</" + TAG_ERROR + ">";
Hashtable<String, String> receivedContentTypes = new Hashtable<String, String>();
/**
* Maintain a list with received files and their content types.
*/
Hashtable<String, File> receivedFiles = new Hashtable<String, File>();
/**
* Override executeAction to save the received files in a custom place
* and delete this items from session.
*/
@Override
public String executeAction(HttpServletRequest request, List<FileItem> sessionFiles) throws UploadActionException {
String response = "";
@SuppressWarnings("unused")
int cont = 0;
for (FileItem item : sessionFiles) {
if (false == item.isFormField()) {
cont ++;
try {
/// Create a temporary file placed in the default system temp folder
File file = File.createTempFile("upload-", ".bin");
item.write(file);
/// Save a list with the received files
receivedFiles.put(item.getFieldName(), file);
receivedContentTypes.put(item.getFieldName(), item.getContentType());
/// Send a customised message to the client.
response += file.getAbsolutePath();
} catch (Exception e) {
throw new UploadActionException(e);
}
}
}
/// Remove files from session because we have a copy of them
removeSessionFileItems(request);
/// Send your customised message to the client.
return response;
}
/**
* Get the content of an uploaded file.
*/
@Override
public void getUploadedFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
String fieldName = request.getParameter(UConsts.PARAM_SHOW);
File f = receivedFiles.get(fieldName);
if (f != null) {
response.setContentType(receivedContentTypes.get(fieldName));
FileInputStream is = new FileInputStream(f);
copyFromInputStreamToOutputStream(is, response.getOutputStream());
} else {
renderXmlResponse(request, response, XML_ERROR_ITEM_NOT_FOUND);
}
}
/**
* Remove a file when the user sends a delete request.
*/
@Override
public void removeItem(HttpServletRequest request, String fieldName) throws UploadActionException {
File file = receivedFiles.get(fieldName);
receivedFiles.remove(fieldName);
receivedContentTypes.remove(fieldName);
if (file != null) {
file.delete();
}
}
}
我只是将这一行注释掉(“protected static final String XML_ERROR_ITEM_NOT_FOUND = "<" + TAG_ERROR + ">item not found";"),重新编译并运行它,它工作正常。我希望这一切对其他人有所帮助。感谢 Braj 的帮助。