2012-07-03 66 views
0

我对portlet有问题。当我写在portlet.xml标准线Portlet块jsp页面

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

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

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

jsp页面中的java代码不执行。我不是在谈论view.jsp即时通讯关于从view.jsp调用的页面。

我认为问题的doView()从门户

uploadport.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 

} 
} 

为什么它heppening?

+0

它是否进入'doView'?顺便说一句:有'错误'作为实例变量将无法正常工作 - 您的portlet必须是线程安全的... – home

+0

我的英语不好。如果我正确地理解了你,你说这个portlet不能影响jsp页面吗? –

+0

NP。我只是想知道'doView'是否被执行。添加类似日志语句的内容... – home

回答

0

此问题已得到解决。
1.需要使用MVC portletGeneric Portlet
2.删除doView()从门户

这一切。但是这是另一个问题。
1. MVC portlet不是最好的选择。
2.如何将参数发送到view.jsp从portlet没有doView()