Struts ForwardActionの例

Struts ForwardActionの例

このStrutsForwardActionの例をダウンロード–Struts-ForwardAction-Example.zip

Struts MVCモデルでは、新しいビューページを取得するためにアクションコントローラーを検討する必要があります。 場合によっては、指定されたJSPページのみを取得するだけでよく、ページを単に転送するアクションコントローラークラスを作成するのは非常に愚かです。たとえば、

public ActionForward execute(ActionMapping mapping,ActionForm form,
    HttpServletRequest request,HttpServletResponse response)
        throws Exception {

    return mapping.findForward("success");
}
   
    
   

Strutsには、ForwardAction(org.apache.struts.actions.ForwardAction)と呼ばれる特別なアクションコントローラークラスが付属しており、名前どおりに「forward-only」タスクを実行し、指定されたJSPページにアクセスできます。直接。

/Welcome」Webパスを宣言し、属性をForwardActionクラスとして入力して、Welcome.jspページに転送します。

struts-config.xml





    

        

    

Welcome.jsp

This is Welcome Page

index.jspページを作成します。ユーザーがリンクをクリックすると、「/Welcome」に転送されます(Welcome.jspを返します)。

ForwardAction Example

http://localhost:8080/StrutsExample/、リンクをクリックします。

struts-forwardaction-example1

struts-forwardaction-example2