Friday, December 30, 2011

Struts2 upload file and ajax Examples

This is the sample code for file upload example in Struts 2 using event handling mechanism
/*******************************************************************************\
******************************


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<s:head theme="ajax" />
<link href="<s:url value="/css/campaign.css"/>" rel="stylesheet"
   type="text/css"/>
     <title>upload and ajax test</title>
</head>
<script>
  function changeApplication()

{
        dojo.event.topic.publish("change_Application");
  }
  </script>
<body>
<s:url id="updateSecondList" action="updateSecondList" />
   
    <s:actionerror />
    <s:fielderror />
     <s:form id="test_form" name="test_form" action="FileAction"
method="POST" theme="ajax" enctype="multipart/form-data">
     
         <s:select
             label="First List"
            list="firstList"
            name="selectedItem"
            onchange="javascript:changeApplication();return false;">
        </s:select>
       
        <tr>
        <td class="tdLabel"><label class="label">Second List</label></td>
        <td>
   
    <s:div showLoadingText="false"
             id="details" href="%{updateSecondList}" theme="ajax"
             listenTopics="change_Application" formId="test_form">
         </s:div>                           
        </td>
       
</tr>
       
        <s:file name="upload" label="File"/>
        <s:submit />
     </s:form>
</body>
</html>
/*******************************************************************************\
**************************/

No comments:

Post a Comment