签名Applet和服务器端控制器之间的通信 [英] Communication between Signed Applet and server side Controller

查看:238
本文介绍了签名Applet和服务器端控制器之间的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个签名的applet上传文件到服务器。 code运行良好,但我想从applet的文件发送到服务器端控制器,其中code已经把保存该文件到服务器。

I have created a signed applet for uploading a file to server. Code is running fine but I want to send that file from applet to server side controller where the code has placed to save that file to server.

我的SENDFILE code在签署Applet的:

public static void sendFile(String destFileName) throws IOException {       
        String filePrivacy = "Public";
        String fileKeyword = "uploadFileDocumentName";
        String fileComments = "fileComments";
        String fileType = "txt";
        String fileFolder = "/Works";
        String fileDetails = "";
        HttpClient client = new HttpClient();
        PostMethod postMethod = new PostMethod(
                "http://localhost:8080/fileUpload/encryptFileUpload.works?filePrivacy="+filePrivacy+"&fileKeyword="+fileKeyword+"&fileComments="+fileComments+"&fileType="+fileType+"&fileFolder="+fileFolder+"&fileDetails="+fileDetails);

        File f = new File(destFileName);
        Part[] parts = {new FilePart(f.getName(), f)};
        postMethod.setRequestEntity(new MultipartRequestEntity(parts, postMethod.getParams())); 
        postMethod.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1");
        client.executeMethod(postMethod);
        postMethod.releaseConnection();
    }

和我的UploadController的方法是这样的:

@RequestMapping(value = "/encryptFileUpload.works")
    public String uploadEncryptFile(String filePrivacy,
            String fileKeyword,
            String fileComments,
            String fileType,
            String fileFolder,
            HttpServletRequest request, HttpServletResponse response) {
        try {
            Map<String, Object> requestMap = new HashMap<String, Object>();
            requestMap.put(DMSConstants.JCR_FILE_PRIVACY, filePrivacy);
            requestMap.put(DMSConstants.JCR_FILE_KEYWORD, fileKeyword);
            requestMap.put(DMSConstants.JCR_FILE_COMMENTS, fileComments);
            requestMap.put(DMSConstants.JCR_FILE_TYPE, fileType);
            MultipartHttpServletRequest m = (MultipartHttpServletRequest) request;
            MultipartFile file = m.getFile("Filedata");
            Node folderNode = contentPublishService.getFolderNode(fileFolder);
            Node node = contentPublishService.saveFileToRepository(folderNode,
                    file.getInputStream(), file.getOriginalFilename(),
                    requestMap);
        } catch (RepositoryException e) {
            e.printStackTrace();        
        return null;
    }

在该行 MultipartHttpServletRequest M =(MultipartHttpServletRequest)请求; 我越来越喜欢异常:

java.lang.ClassCastException: org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
    at com.nmmc.works.web.controller.FileUploadController.uploadEncryptFile(FileUploadController.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)

那么,是走错了,我应该在我的code做什么样的变化。而第二件事是谁我可以在控制器获取文件?

So where is going wrong and what changes should i do in my code. And second thing is who can i get file at controller?

推荐答案

需要更多的细节...

Need more details...

只是一些建议...

什么是的部分的对象是什么?

What is the Part object is?

如果你想通过上传文件'零件'我可能会建议只是覆盖的 MultipartEntity 的方法的writeTo上传大文件,而不是使用数组,或者也许是没有的事?

If you want to upload file by 'parts' I may recommend just to override MultipartEntity writeTo method to upload big file instead of using arrays or maybe it is not the thing?

就铸造......我可以猜测该行可能会导致问题。

Concerning the cast... I may guess that line may cause the problem

MultipartHttpServletRequest m = (MultipartHttpServletRequest) request;

作为规则的HttpClient工作在削减用的FileUpload库。那么,为什么不能用它代替?

As a rule HttpClient is working in pare with FileUpload lib. So why not to use it instead?

还有一件事......你点内容哑剧为文本/ XML 但它是XML尤其是如果它是一个二进制文件的一部分?难道不应该是某种应用程序/八位字节流呢?

And one more thing... you point the content mime as text/xml but is it xml especially if it is a bin file part? Shouldn't it be some kind of application/octet-stream instead ?

无论如何,这将是更有帮助你在你的问题提供更多的细节。

Anyway, that would be more helpful you to provide more details in your question

这篇关于签名Applet和服务器端控制器之间的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆