【发布时间】:2012-12-31 15:55:04
【问题描述】:
通过从 jsp 页面运行小程序,由于 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";
}
【问题讨论】:
-
首先使用 HTML 和带有硬编码参数的
applet元素使其工作。然后使用deployJava.js部署它。 -
这现在没有帮助,但你不应该试图从你的代码库中删除小程序吗???
-
@AndrewThompson:谢谢。我曾尝试使用硬编码参数,但无法运行它。但现在我找到了解决方案。我已将 Jar 文件放在资源文件夹中,以便可以公开访问它,并且我可以访问 MainApplet8 类
-
很高兴你把它整理好了。 :) 当网站允许时,您可以输入最后一条评论作为答案并accept 它。
标签: java spring-mvc applet