1

通过从 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";
}   
4

1 回答 1

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

于 2013-01-18T06:39:24.387 回答