2011-10-12 3 views
1

액션 서블릿 createLabel.do를 호출하려고하는데 액션 클래스가 호출되지 않는 것처럼 보입니다. 난 방화 광을 사용하여 디버깅하고 그것은 URL이 호출 된 것처럼 보이지만 수신 응답이 없습니다. 여기 Struts 액션에 대한 Ajax 호출이 응답을 반환하지 않습니다.

public class CreateLabelAction extends Action{ 

public ActionForward execute (ActionMapping mapping, HttpServletRequest request, HttpServletResponse response){ 


    String label = request.getParameter("label"); 

    String lab_no = request.getParameter("lab_no"); 
    String accNum = request.getParameter("accNum"); 

    response.setContentType("application/json"); 
    try { 
     DB db = new DB(DB.DATA); 
     Connection conn = db.GetConnection(); 
     String insertstmt = "update Info set label='"+label+"' where lab_no="+lab_no+" and accNum='"+accNum+"'"; 
     logger.info(insertstmt); 

     PreparedStatement pstmt = conn.prepareStatement(insertstmt); 
     pstmt.executeUpdate(); 
     pstmt.close(); 
     db.closeConn(); 

     logger.info("Label created successfully."); 


    } catch (Exception e){ 
     logger.error("Error inserting label into Info" + e); 
     request.setAttribute("error", "There was an error creating a label."); 

    } 

    logger.info("Label ="+label); 
    label = StringEscapeUtils.escapeJavaScript(label); 
      return mapping.findForward("complete"); 
} 

} 

이 스트럿 - config.xml 파일의 구성은 다음과 같습니다 :

<script type="text/javascript" charset="utf-8"> 
    $(function() { 
      $("#createLabel").click(function() { 
      $.ajax({ 
       type: "POST",  
       url: "/createLabel.do", 
       dataType: "json", 
       contentType: "application/json; charset=utf-8", 
       data: { lab_no: $("#labNum").val(),accNum: $("#accNum").val(), label: $("#label").val() }, 
       success: function() { 
        alert("success"); 
       } 
      }); 
      }); 
    }); 

</script> 

가 여기 내 액션 클래스의 :
다음은 자바 스크립트 함수의

<action input="/labDi.jsp" name="LabelForm" path="/createLabel" scope="request" type="all.pageUtil.CreateLabelAction"> 
     <forward name="complete" path="/labDi.jsp" /> 
    </action> 

누군가가 말해 주시겠습니까 이유 액션 클래스가 유발되지 않았습니까? 미리 감사드립니다.

+0

'#의 createLabel'는 DOM 요소의 유형은 무엇입니까? 제출 버튼, 링크, 표준 버튼, div, ...? –

+0

표준 단추 : Sapphire

+0

이 단추는 양식 안에 있습니까? FireBug에서 버튼을 클릭하면 무엇을 볼 수 있습니까? AJAX 요청이 전송됩니까? –

답변

1

processRequest이라는 메서드 내에서 동작을 정의하고 있습니다 (DispatchAction이 아니고 토큰 매개 변수를 포함하지 않은 경우와 그렇지 않은 경우).

Struts 1의 기본 요청 처리 방법은 execute입니다.

1.x의 : http://struts.apache.org/1.x/apidocs/org/apache/struts/action/Action.html

1.2 : http://struts.apache.org/1.2.9/api/org/apache/struts/action/Action.html

1.1 : http://struts.apache.org/1.1/api/org/apache/struts/action/Action.html

나는 당신이이 일을 기대하고 이유를 알고하지 않습니다. 정상적인 Struts 1 요청을 처리하기위한 "action servlet"을 생성한다면, 잘못 처리하고있는 것입니다. Struts 요청은 가장 예외적 인 상황을 제외하고는 모두 Action (올바르게 서브 클래 싱)에 의해 처리됩니다.

조치 서블릿은 Struts를위한 요청을 캡처하고 적절한 Struts 요청 프로세서를 사용하여 요청의 조치를 찾아 호출합니다. (다른 관련 하우스 키핑 작업과 함께)

정말 Struts 1 튜토리얼이나 문서를 확인해 보시기 바랍니다.

+0

ok 이제 processRequest 메소드를 변경했습니다. 변경된 코드를 확인하십시오. 여전히 작동하지 않습니다. – Sapphire

+0

@Sapphire 아직 올바른 서명이 아닙니다. 액션 맵핑 설정을 잘 포함시켜야합니다. –

+0

? 위에 표시된 것처럼 struts-config.xml에 forward name "complete"를 포함 시켰습니다. 이것이 의미하는 것이면. – Sapphire

0

// 여기에 struts 액션 클래스에 요청을 보내는 작업 아약스 코드가 있습니다. // 행운

function userExists(userid){ 
      var exists = false; 
       $.ajax({ 
        type: "POST", 
        url: "./searchUser.do", 
        data: "userid=" + userid, 
        success: function(response){ 
         exists = true; 
        }, 
        error: function(e){ 
         alert('Error: ' + e); 
        } 
       }); 
      return exists; 
      } 

..

하리

관련 문제