异常:javax.Servlet.servletException:Servlet执行抛出异常org.apache.tomcat.websocket.server.wsfilter.doFilter(wsfilter.java:52)
根源:java.lang.linkageError:loader约束违反:loader(org/eclipse/osgi/internal/loader/equinoxClassLoader实例)以前为另一个类型启动了加载,该类型名为“javax/servlet/http/httpServletResponse”testproject.downloadServiceHandler.service(ET(rwtservlet.java:100)javax.servlet.http.httpservlet.service(httpservlet.java:635)javax.servlet.http.httpservlet.service(httpservlet.java:742)org.eclipse.rap.rwt.osgi.internal.cutoffContextPathWrapper.service(CutoffContextPathWrapper.java:106)org.eclipse.equinox.http.servlet.internal.httpServiceRegistration.service(endpointRegistration.javaORG.ECLIPSe.equinox.http.servlet.internal.servlet.responseStateHandler.processRequest let.java:742)org.apache.tomcat.websocket.server.wsfilter.doFilter(wsfilter.java:52)
以下是我的代码和相关文件:
basicapplication.java
package testproject;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.rap.rwt.application.Application;
import org.eclipse.rap.rwt.application.ApplicationConfiguration;
import org.eclipse.rap.rwt.client.WebClient;
public class BasicApplication implements ApplicationConfiguration {
public void configure(Application application) {
Map<String, String> properties = new HashMap<String, String>();
properties.put(WebClient.PAGE_TITLE, "Test Project");
application.addEntryPoint("/", BasicEntryPoint.class, properties);
}
}
basicentrypoint.java
package testproject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.application.AbstractEntryPoint;
import org.eclipse.rap.rwt.client.service.UrlLauncher;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
public class BasicEntryPoint extends AbstractEntryPoint {
@Override
protected void createContents(Composite parent) {
parent.setLayout(new GridLayout(2, false));
Button downloadButton = new Button(parent, SWT.PUSH);
downloadButton.setText("Download");
downloadButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
try {
File testfile = new File("/home/user/Desktop/test.file");
byte[] fileContent = Files.readAllBytes(testfile.toPath());
sendDownload(fileContent, testfile.getName());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
}
public boolean sendDownload(byte[] data, String filename) {
DownloadServiceHandler service = new DownloadServiceHandler(data, filename);
service.register();
UrlLauncher launcher = RWT.getClient().getService(UrlLauncher.class);
launcher.openURL(service.getURL());
return true;
}
}
package testproject;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.rap.rwt.service.ServiceHandler;
public class DownloadServiceHandler implements ServiceHandler {
private final byte[] data;
private final String filename;
private String id;
public DownloadServiceHandler(byte[] data, String filename) {
this.data = data;
this.filename = filename;
this.id = calculateId();
}
public String getURL() {
return RWT.getServiceManager().getServiceHandlerUrl(getId());
}
private String getId() {
return id;
}
private String calculateId() {
return String.valueOf(System.currentTimeMillis()) + data.length;
}
public boolean register() {
try {
RWT.getServiceManager().registerServiceHandler(getId(), this);
return true;
} catch (Exception e) {
System.out.println("failed to register download service handler");
return false;
}
}
private boolean unregister() {
try {
RWT.getServiceManager().unregisterServiceHandler(getId());
return true;
} catch (Exception e) {
System.out.println("failed to unregister download service handler");
return false;
}
}
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
try {
response.setContentType("application/octet-stream"); // this is the error line "DownloadServiceHandler.java:59"
response.setContentLength(data.length);
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename
+ "\"");
response.getOutputStream().write(data);
} catch (Exception e) {
System.out.println("failed to dispatch download");
} finally {
unregister();
}
}
}
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Testproject
Bundle-SymbolicName: testproject
Bundle-Version: 1.0.0.qualifier
Automatic-Module-Name: testproject
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.rap.rwt;bundle-version="[3.0.0,4.0.0)"
Service-Component: OSGI-INF/contribution.xml
Import-Package: javax.servlet;version="3.1.0",
javax.servlet.http;version="3.1.0"
Bundle-ClassPath: .
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="BasicApplication">
<implementation class="testproject.BasicApplication"/>
<service>
<provide interface="org.eclipse.rap.rwt.application.ApplicationConfiguration"/>
</service>
</scr:component>
我自己找到了解决办法....
我仅使用javax.servlet3.1.0版来限制我的项目。也许我安装的Tomcat服务器版本不支持。我不确定这一点,但我修改了meta-inf/manifest.mf中的以下部分,问题得到了修复。
import-package:javax.servlet;version=“[2.3.0,4.0.0)”,javax.servlet.http;version=“[2.3.0,4.0.0)”
我需要创建一个 Servlet,它提供来自外部服务器的文件并将其发送给用户。 因为我不希望servlet成为“中间人”,所以我需要它来服务文件,而不会将其预先传输给自己,然后重新提交给用户以解决性能问题(否则每次下载至少需要2倍它需要的时间-不谈论这些服务器之间的速度瓶颈。 这有可能吗? 谢谢!
我不明白为什么这这么难,每个人都有自己的实现... 所以在我的服务器中,我生成了一个文件,我希望用户能够在点击后下载。 所以我设置了请求,服务器成功地接收到了请求,现在,我正在努力将字节数组写入输出。 这是我的回应代码:
我试图根据此链接下载siteminder试用版。但是在谷歌上搜索某个地方时,它说siteminder即使对于像Oracle(Express Edition)这样的开发也不是免费的。请澄清我对此的疑问。如果有试用版,请直接到那里找我。提前谢谢。
一个简易的从服务器下载txt文件格式书籍的demo。Demo代码包括两部分,一部分是iOS客户端,一部分是服务器端php代码。在本机测试需要在Mac机器上先运行服务器端php代码,才能运行iOS客户端正常进行下载书籍并显示。 作者说:第一次发代码,欢迎拍砖。用到的东西包括: 1、asihttper的队列下载和json解析; 2、storyboard方式下tableview的push以及传值。 现有
我在Localhost中正确上传我的文件,但是当我在服务器上上传我的应用程序时,他们给我错误:上传文件后服务器错误。 这是我的控制器: 在我的本地主机中,文件保存在公用文件夹中。我想用public\u html或public\u html/image将我的文件保存在我的服务中。