2012-08-07 57 views

回答

0

您可以創建一個servlet並將其註冊到servlets.xml中(OpenXava在部署時將此文件的內容添加到web.xml中)。

要爲用戶啓用servlet,請創建一個實現IForwardAction的操作。

例如servlet.xml中可能有:

<servlet> 
    <servlet-name>myDownloadServlet</servlet-name> 
    <servlet-class>org.webapp.test.MyDownloadServlet</servlet-class> 
</servlet>   

<servlet-mapping> 
    <servlet-name>myDownloadServlet</servlet-name> 
    <url-pattern>/mydownload.do</url-pattern> 
</servlet-mapping> 

而且MyDownloadServlet類。

public class MyDownloadServlet extends HttpServlet { 
    /** 
    * Shows Hello World. 
    */ 
    @Override 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     response.setContentType("text/html"); 
     response.getWriter().write("Hello World"); 
    } 

    @Override 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     doGet(request, response); 
    } 
} 

最後你的行動

public class MyDownloadAction extends ViewBaseAction implements IForwardAction { 

    public String getForwardAction() { 
     return "/mydownload.do"; 
    } 

    public boolean inNewWindow() { 
     return true; 
    } 
} 

費德里科

相關問題