2013-01-17 22 views
1

通過從jsp頁面運行小程序,由於彈簧安全性,映射得到更改。 我已經使用Spring MVC創建了Maven項目。 這是我的jsp的網頁Spring MVC中的Applet:ClassNotFound

<%@ 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中的錯誤日誌:

WARN:org.springframework.web.servlet.PageNotFound - 在Dispat中找不到URI的HTTP請求映射[/ eSenseReengineering/tc-teacher/rs/MainApplet8]名爲 'appServlet'

注cherServlet:

@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"; 
} 
+1

首先使用HTML和帶有硬編碼參數的'applet'元素來獲得它的工作。然後使用['deployJava.js'](http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/deployment_advice.html#deplToolkit)進行部署。 –

+0

這不會幫助你現在,但不應該試圖擺脫你的代碼庫中的小程序? –

+0

小蘋果是邪惡的。 +1 – user

回答

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的路徑,我從下面的方法重定向Jsp頁面:/resources/lib/Applet.jar