2011-08-21 1 views
1

저는 struts 1.2를 사용하고 있습니다. 내 struts 흐름이 제대로 작동하지만 validate() 메서드를 사용하여 유효성 검사를 수행하고 있습니다. 내 양식이 자동으로 제출됩니다. 이 유효성 검사 메소드가 호출됩니다.validate()를 사용할 때 Struts 폼이 자동으로 제출됩니다. menthod

스트럿츠의 정상적인 동작인지 또는 일부 구성이 응용 프로그램에 없음을 확신하지 못합니다.

이해해주세요. 다음 는 설정과 코드입니다

<action path="/Postaddd" 
      type="bseller.postadd.PostaddAction" 
      parameter="dispatch" 
      scope="request" 
      validate="true" 
      name="PostadddForm"> 
     <forward name="posterror" path="ordererror.page"/> 
     <forward name="successPost" path="bseller.successPost.page"/> 

    </action>  public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) 
    { 


     Logger log= Logger.getLogger("BSELLER_APPLICATION"); 
     log.info("validate method called"); 
     ActionErrors errors = new ActionErrors(); 

      log.info("Email Id: " + getEmailid()); 
      if(!Validation.isValidEmailAddress(getEmailid())) 
        { 
       errors.add("emailid", new ActionMessage("prompt.email.error")); 
        } 
      if(!Validation.isPhoneNumberValid(getMobile())) 
      { 
       errors.add("mobile", new ActionMessage("prompt.contactno.error")); 
      } 

      if(!Validation.isNumeric(getPrice())) 
      { 
       errors.add("price", new ActionMessage("prompt.price.error")); 
      } 


     return errors; 
    } 

///////////////

<%@ page contentType="text/html;charset=UTF-8" language="java"%> 
<%@ taglib uri="/WEB-INF/displaytag.tld" prefix="display" %> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> 
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> 
<%@ taglib uri="/WEB-INF/c.tld" prefix="c"%> 

<%@ page import="bseller.utils.*" %> 

<%@ page import="java.util.*" %> 

<%@page import="bseller.utils.CategorydetailObject"%> 
<%@page import="org.apache.struts.taglib.logic.IterateTag"%><head> 
<title><bean:message key="homepage.title" /></title> 
<html:base /> 
<style type="text/css"> 
@import url("<%=request.getContextPath()%>/css/main.css"); 
@import url("<%=request.getContextPath()%>/css/submitpost.css"); 

</style> 

<script language="javascript" src="jquery_mini.js"></script> 
<script language="javascript" src="jquery.dimensions.js"></script> 
<script language="javascript" src="js/Ajax_Function.js"></script> 
<script language="javascript"> 



    var name = "#floatMenu"; 


    var menuYloc = null; 

     $(document).ready(function(){ 

      menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px"))) 
      $(window).scroll(function() { 
       offset = menuYloc+$(document).scrollTop()+"px"; 
       $(name).animate({top:offset},{duration:500,queue:false}); 
      }); 
     }); 
    </script> 
    <script> 
    function ret_home() 
    { 
    alert("home"); 
    return false; 
    } 
    function ret_aboutus() 
    { 
    alert("about us"); 
    return false; 
    } 
    function ret_contactus() 
    { 
    alert("contact us"); 
    return false; 
    } 

    function getSubcatValue(categoryValue) 
    { 
    //alert(document.getElementById("categorySelect").Value); 
    document.getElementById("categorySelect").Value =categoryValue; 
    //alert(document.getElementById("categorySelect").Value); 
     //alert(categoryValue); 
     //var data="catvalue="+categoryValue; 
     //alert(data); 
     //datafromajax=""; 
    // alert("before1"+datafromajax); 
     var url="Subcategory_Ajax.jsp?catvalue="+categoryValue; 
     sendRequest(url); 
     //alert("after"+datafromajax); 
     //datafromajax=""; 
     document.getElementById("categorySelect").Value=""; 
    } 

    /*function setUploadImageOption(ordertype); 
    { 

     if(ordertype=="Required") 
     { 
      //document.getElementById("UploadImage").visible= false; 
      document.getElementById('UploadImage').style.visibility = 'hidden'; 
     } 
    }*/ 

    function onchangeSubcat(subcatValue) 
    { 
     // alert(subcatValue); 
     //alert(document.getElementById("subCatSelect").Value); 
     document.getElementById("subCatSelect").Value =subcatValue; 
     //alert(document.getElementById("subCatSelect").Value); 
     //subcatValue=subcatValue; 
    } 



    //populatedropdown 
    </script> 



<style type="text/css"> 
body { 

    height:2000px; 
    color:#111; 
    font:10px "Lucida Grande", "Lucida Sans", "Trebuchet MS", verdana, sans-serif; 
    } 
    #floatMenu { 
     position:absolute; 
     top:200px; 
     left:55%; 
     margin-left:235px; 
     width:200px; 
     } 
     #floatMenu ul { 
      margin-bottom:20px; 
      } 
      #floatMenu ul li a { 
       display:block; 
       border:1px solid #999; 
       background-color:#000; 
       background:'images/tab_bg1.gif' 
       border-left:6px solid #999; 
       text-decoration:none; 
       color:#ccc; 
       padding:5px 5px 5px 25px; 
      } 
      #floatMenu ul li a:hover { 
       color:#fff; 
       background-color:#333333; 
      } 
      #floatMenu ul.menu1 li a:hover { 
       border-color:#09f; 
      } 
      #floatMenu ul.menu2 li a:hover { 
       border-color:#9f0; 
      } 
      #floatMenu ul.menu3 li a:hover { 
       border-color:#f09; 
      } 
</style> 
</head> 
<body> 


<span id="er"></span> 
<%! 

List l; 
HashMap<String ,ArrayList<CategorydetailObject>> hm =null; %> 


<% 
try 
{ 
hm =(HashMap<String ,ArrayList<CategorydetailObject>>)config.getServletContext().getAttribute("PRODUCTS"); 
} 
catch(Exception e) 
{ 
} 
%> 
<input type="hidden" name="subcatfromajax" id="subcatfromajax"></input> 
<DIV class=city><DIV id=welcome></DIV><DIV id=main><DIV id=block><DIV id=header><font size=4 color=blue > 
Post Your Advertisement</DIV><DIV class=blank5></DIV><DIV class=blank5></DIV> 

<html:messages id="" /> 
<html:form action="/Postaddd.do?dispatch=submitPost" method="post" enctype="multipart/form-data" > 
<TABLE cellSpacing=0 cellPadding=0 width='98%'background='images/background_city.gif' border=0><TBODY> 
    <TR> 
    <TD><div class="post_ad_fonts">Email</div><div style="float:left"> 
    <input style="width:162px" type="text" maxlength="64" name="emailid" id="emailid" class="post_ad_field" value='' /> 
    </div> 
<div class="blank10"></div> 
    </TD> 
    </TR> 


    <TR> 

    <TD><DIV id=bb1><div class="post_ad_fonts">City</div><div style="float:left"> 
<select class="post_ad_field" style="width:165px" name='citySelectBox' id='citySelectBox'> 
<option id='0' name='0' value='0'>Select City</option> 
<option name='22' id='22' value='Ahmedabad' >Ahmedabad</option><option name='211001' id='211001' value='Allahabad' >Allahabad</option><option name='23' id='23' value='Bangalore' >Bangalore</option><option name='462001' id='462001' value='Bhopal' >Bhopal</option><option name='24' id='24' value='Chandigarh' >Chandigarh</option><option name='25' id='25' value='Chennai' >Chennai</option><option name='26' id='26' value='Coimbatore' >Coimbatore</option><option name='27' id='27' value='Delhi' >Delhi</option><option name='403108' id='403108' value='Goa' >Goa</option><option name='132222' id='132222' value='Gurgaon' >Gurgaon</option><option name='580020' id='580020' value='Hubli' >Hubli</option><option name='28' id='28' value='Hyderabad' >Hyderabad</option><option name='142222' id='142222' value='Indore' >Indore</option><option name='152222' id='152222' value='Jaipur' >Jaipur</option><option name='144001' id='144001' value='Jalandhar' >Jalandhar</option><option name='831001' id='831001' value='Jamshedpur' >Jamshedpur</option><option name='421301' id='421301' value='Kalyan' >Kalyan</option><option name='208001' id='208001' value='Kanpur' >Kanpur</option><option name='29' id='29' value='Kochi' >Kochi</option><option name='30' id='30' value='Kolkata' >Kolkata</option><option name='162222' id='162222' value='Lucknow' >Lucknow</option><option name='141001' id='141001' value='Ludhiana' >Ludhiana</option><option name='625001' id='625001' value='Madurai' >Madurai</option><option name='575001' id='575001' value='Mangalore' >Mangalore</option><option name='31' id='31' value='Mumbai' >Mumbai</option><option name='32' id='32' value='Mysore' >Mysore</option><option name='172222' id='172222' value='Nagpur' >Nagpur</option><option name='422001' id='422001' value='Nashik' >Nashik</option><option name='400701' id='400701' value='NaviMumbai' >NaviMumbai</option><option name='201301' id='201301' value='Noida' selected>Noida</option><option name='800001' id='800001' value='Patna' >Patna</option><option name='33' id='33' value='Pune' >Pune</option><option name='360001' id='360001' value='Rajkot' >Rajkot</option><option name='182222' id='182222' value='Surat' >Surat</option><option name='400601' id='400601' value='Thane' >Thane</option><option name='620015' id='620015' value='Trichy' >Trichy</option><option name='695001' id='695001' value='Trivandrum' >Trivandrum</option><option name='390001' id='390001' value='Vadodara' >Vadodara</option><option name='520001' id='520001' value='Vijayawada' >Vijayawada</option><option name='531001' id='531001' value='Vizag' >Vizag</option></select> 
<input type='hidden' name='city' id='city' value='201301'/> 
</div> 
<div class="blank10"></div> 
</div> 
</TD></TR> 

<TR> 
    <TD> 
    <div class="post_ad_fonts">Category</div> 
    <div style="float:left"> 
    <select class="post_ad_field" style="width:165px" name='categorySelect' id='categorySelect'" onchange="getSubcatValue(this.value);"> 
    <option id='0' value='0'>Select Category</option> 
    <% 
    Set<Map.Entry<String,ArrayList<CategorydetailObject>>> set =hm.entrySet(); 

    for(Map.Entry<String,ArrayList<CategorydetailObject>> me: set) 
    { 
     String cat= me.getKey(); 
    %> 

    <option name="<%=cat %>" id="<%=cat %>" value="<%=cat %>"> <%=cat %></option> 
    <% 
    } 

    %>  
    </select> 
    <input type='hidden' name='categorySelect' id='categorySelect' value=''/> 
    </div> 
    <div class="blank10"></div> 
    </TD> 
</TR> 

<TR> 
    <TD> 
    <div class="post_ad_fonts">SubCategory</div> 
    <div style="float:left"> 
    <select class="post_ad_field" style="width:165px" name='subCatSelect' id='subCatSelect' onchange="onchangeSubcat(this.value);"> 
    <option id='0' value='0'>Select SubCategory</option> 
    </select> 
    <input type='hidden' name='subCatSelect' id='subCatSelect' value=''/> 

    </div> 
    <div class="blank10"></div> 
    </TD> 
</TR> 

<TR> 
    <TD> 
    <DIV id=bb1><div class="post_ad_fonts">Head Line</div> 
    <div style="float:left"> 
    <input style="width:440px" type="text" maxlength="64" name="headline" id="headline" class="post_ad_field" value='' /> 
</div> 
<div class="blank10"></div> 
</div> 

    </TD> 
</TR> 
<TR> 
    <TD> 
    <DIV id=bb1><div class="post_ad_fonts">Description</div> 
    <div style="float:left;width :440px;"> 
    <table border="0" style="margin:0px"><tr><td><div id="showbar">Loading Html Editor...<img src="images/ajax_loader.gif" alt="loading"/></div></td></tr></table> 
<textarea name="description" id="description " onfocus="if(this.value=='Adding more detail here will help you get more responses.')this.value='';" style="width:440px;height:170px">Adding more detail here will help you get more responses.</textarea> 

</div> 
</div> 


    </TD> 
</TR> 


<TR> 
    <TD> 
    <div class="post_ad_fonts">Mobile No.<br/><span style="font-weight:normal">(Optional)</span></div> 
<div style="float:left"> 
    <input style="width:162px" type="text" maxlength="14" name="mobile" id="mobile" class="post_ad_field" value="" />  
</div> 
<div class="blank10"></div> 

    </TD> 
</TR> 

<TR> 
    <TD> 
    <div class="post_ad_fonts">Price<br/><span style="font-weight:normal">(Optional)</span></div> 
<div style="float:left"> 
    <input style="width:162px" type="text" maxlength="14" name="price" id="price" class="post_ad_field" value="" />  
</div> 
<div class="blank10"></div> 

    </TD> 
</TR> 

<TR> 
    <TD> 
    <div class="post_ad_fonts">Owner type<br/></div> 
<div style="float:left"> 
    <select class="post_ad_field" style="width:165px" name='owner' id='owner'> 
<option id='0' name='0' value='0'>Individual</option> 
<option name='22' id='22' value='Ahmedabad' >Broker</option></select> 
<input type='hidden' name='ownertype' id='ownertype' value='Individual'/> 
</div> 
<div class="blank10"></div> 
</TD> 
</TR> 

<TR> 
    <TD> 
    <div class="post_ad_fonts">Order type<br/></div> 
<div style="float:left"> 
<select class="post_ad_field" style="width:165px" name='order' id='order'"> 
<option id='0' name='0' value='Available'>Available</option> 
<option name='22' id='22' value='Required' >Required</option></select> 
<input type='hidden' name='ordertype' id='ordertype' value='Available'/> 
</div> 
<div class="blank10"></div> 
</TD> 
</TR> 





<TR> 
    <TD> 
    <div class="post_ad_fonts">Upload Image<br/></div> 
<div style="float:left" id="UploadImage"> 

    <html:file property="image1"></html:file> 
    <html:file property="image2"></html:file> 
    <html:file property="image3"></html:file> 
<input type="file" name="image4"> 
</div> 
<div class="blank10"></div> 

    </TD> 
</TR> 
<tr><td><div class="post_ad_fonts"><br/></div><div style="float:middle"><html:submit>POST ORDER</html:submit></div> </td></tr> 
</TBODY></TABLE></html:form></DIV></DIV></DIV><DIV class=blank10></DIV></DIV></DIV> 


<div id="floatMenu"> 
    <ul class="menu1"> 
    <li><a href="#" onclick="return ret_home();"> Home </a></li> 
    </ul> 
    <ul class="menu2"> 
    <li><a href="#" onclick="return ret_aboutus();"> About Us </a></li> 
    <!--<li><a href="#" onclick="return false;"> </a></li> 
    <li><a href="#" onclick="return false;"> </a></li>--> 
    </ul> 
    <ul class="menu3"> 
    <li><a href="#" onclick="return ret_contactus();"> Contact Us </a></li> 
    </ul> 
</div> 
+0

요청 하시겠습니까?/Postaddd? 그렇다면 정상입니다. –

+0

우리는/postadd를 대상으로하는 형식을 가진 jsp를 요청하고 있지만 그 jsp를 때릴 것입니다. 그 폼은 자동으로 제출됩니다. (validate()를 사용할 때) 그렇지 않으면 잘 동작합니다. – Pedantic

+0

일부 자바 스크립트가있는 경우 jsp를 확인해야합니다. –

답변

0

양식이 제출 될 때의 ActionForm의 validate 메소드가 항상 호출된다. 당신은 자신의 방식대로 스트럿츠를 다시 구현하지 않으면 수동으로 호출 할 수 없습니다. 메서드가 validate 메서드와 동일한 작업을 수행하기를 원할 경우 validate 메서드의 코드를 다른 메서드로 옮기고 validate 메서드에서 호출합니다. 나는 당신이하려고하는 것을 완전히 이해하지 않으므로 좀 더 구체적으로 말하십시오.

+0

고마워요. 나는 validate() 메서드를 호출 했으므로 언급하고있다. 해당 jsp를 요청할 때 내 양식이 자동 제출됩니다. 이것은 validate() 메서드를 사용할 때만 발생합니다. 그리고이 방법을 사용하지 않을 때 작동합니다. 그래서 나는 이것이 왜 일어나고 있는지 완전히 혼란 스럽습니다. 그것을 이해하도록 도와주세요. 시간을내어 주셔서 감사합니다 – Pedantic

+0

ur struts-config.xml에서이 작업 매핑 사양을 공유 할 수 있습니까? 또한 validate 메소드를 사용하여 어디에 있는지 확인하는 것이 좋습니다. – MozenRath

+0

나는 hv 내 질문을 편집하시기 바랍니다 – Pedantic