0

我有一个关于 portlet 的问题。当我在portlet.xml标准行中写

<portlet-class>com.liferay.util.bridges.mvc.MVCPortlet</portlet-class>

我的jsp页面工作正常。但是当我添加我的 portlet 类时

<portlet-class>test.uploadport</portlet-class>

jsp页面中的java代码不执行。我不是在谈论我在view.jsp谈论从 调用的页面view.jsp

我认为来自 portlet 的 doView() 有问题

上传端口.java

package test;

import java.io.*;
import java.util.Iterator;
import java.util.List;

import javax.portlet.*;


import org.apache.commons.fileupload.*;
import org.apache.commons.fileupload.disk.*;
import org.apache.commons.fileupload.portlet.*;
import org.apache.commons.fileupload.servlet.*;
import org.apache.commons.fileupload.util.*;
public class uploadport extends GenericPortlet {
private String error;
public void doView(RenderRequest req, RenderResponse res)
throws IOException, PortletException
{
 WindowState state = req.getWindowState();
 res.setContentType("text/html");
 PortletSession session = req.getPortletSession(true);
 PortletContext context = getPortletContext();
 PortletRequestDispatcher rd;
 rd = context.getRequestDispatcher("/view.jsp");
 rd.include(req, res);

}
public void processAction(ActionRequest req, ActionResponse res)
throws IOException, PortletException
{
System.out.println("VASAY - PIROZJOK");
    PortletSession session = req.getPortletSession(true);
    DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
    PortletFileUpload portletFileUpload = new PortletFileUpload(diskFileItemFactory);
    List<FileItem> list=null;
    String mifpath= "1";
    String path = " ";
    String mif = " ";
    String from = "\\\\";
    String to ="/";
    String error="";
    try{
        list = portletFileUpload.parseRequest(req);
        Iterator<FileItem> it = list.iterator();
        //response.setContentType("text/html");
       while ( it.hasNext() ) 
       {

          FileItem item = (FileItem) it.next();
          File disk = new File("C:/uploaded_files/"+item.getName());

    path = disk.toString();

    String code = new String(path.substring(path.lastIndexOf("."), path.length()).getBytes("ISO-8859-1"),"utf-8");
    if (code.equalsIgnoreCase(".zip"))
    {
        System.out.println("PIROZJOK");
        mifpath=path;
        mif = mifpath.replaceAll(from, to);
        item.write(disk);
        error=unzip.unpack(mif, "C:/uploaded_files");
    }
    else
    {
        error = "Выбранный файл не является архивом zip";

    }
  }
}
 catch ( Exception e ) {
 log( "Upload Error" , e);
} 

}
 private void log(String string, Exception e)
   {
// TODO Auto-generated method stub

}
} 

为什么它正在发生?

4

1 回答 1

0

这个问题特别解决了。1.不需要
使用2.从portlet 中 删除MVC portletGeneric Portlet
doView()

就这些。但是还有其他问题。
1.MVC portlet不是最佳选择。
2.如何在view.jsp没有的情况下将参数发送到portlet doView()

于 2012-07-03T07:32:21.397 回答