通过从jsp页面运行applet,由于spring安全性,映射会在线下更改。 我使用Spring MVC创建了Maven项目。 这是我的Jsp页面
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<HTML>
<HEAD>
<TITLE>Java applet example - Passing applet parameters to Java applets</TITLE>
</HEAD>
<BODY>
<object type="application/x-java-applet" height="300" width="550">
<PARAM NAME="Downloadfile" VALUE="${Downloadfile}">
<PARAM NAME="Tempstorage" VALUE="${Tempstorage}">
<param name="archive" value="/webapps/pages/Applet.jar" />
<param name="code" value="MainApplet8" />
</object>
</BODY>
</HTML>
我已将Applet.jar放在:/src/webapps/pages/Applet.jar
这是我的MainApplet.java代码:
public class MainApplet8 extends Applet
{
public void init()
{
String SourceUrl;
final String DestinationPath = getParameter("Tempstorage");
SourceUrl = getParameter("Downloadfile");
System.out.println(SourceUrl + "," + DestinationPath);
File myFile = (File) AccessController.doPrivileged(new PrivilegedAction() {
public Object run()
{
return new File(DestinationPath);
}
});
if (SourceUrl != null && DestinationPath != null) {
try {
URL url = new URL(SourceUrl);
URLConnection con = url.openConnection();
FileOutputStream ot = new FileOutputStream(myFile);
BufferedInputStream in = new BufferedInputStream(
con.getInputStream());
int n;
while ((n = in.read()) != -1) {
ot.write(n);
}
in.close();
ot.close();
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "AA::::" + e.getMessage());
e.printStackTrace();
}
try {
System.out.println("Executing the application");
Desktop.getDesktop().open(new File(DestinationPath));
int processExit = 0;
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "A::" + e.getMessage());
e.printStackTrace();
}
}
}
}
eclipse中的错误日志:
警告:org.springframework.web.servlet.PageNotFound - 在名为'appServlet'的DispatcherServlet中找不到带有URI [/ eSenseReengineering / tc-teacher / rs / MainApplet8]的HTTP请求的映射
注意:我从以下方法重定向Jsp页面:
@RequestMapping(value = "rs/openFile", method = RequestMethod.GET)
public String openFile(@RequestParam(value = "path", required = true) String path, @RequestParam(value="objectName", required = true) String objectName,@RequestParam(value="objectType", required = true) String objectType, Model model, HttpServletRequest request) {
String destinationPath = "D:/temp/"+objectName+"."+objectType;
String hostURL = request.getRequestURL().toString();
hostURL = hostURL.substring(0, hostURL.indexOf(Constants.contextName));
String sourcePath = hostURL+ path;
request.setAttribute("Downloadfile", sourcePath);
request.setAttribute("Tempstorage",destinationPath);
return "test";
}
答案 0 :(得分:0)
在test.jsp文件中完成修改:
<object type="application/x-java-applet" height="300" width="550">
<PARAM NAME="Downloadfile" VALUE="http://127.0.0.1:9090/eSenseData/data/sample.doc">
<PARAM NAME="Tempstorage" VALUE="${Tempstorage}">
<param name="archive" value="<c:url value="/resources/lib/Applet.jar"/>"/>
<param name="code" value="MainApplet8" />
</object>
Applet.jar的路径:/resources/lib/Applet.jar