2014-03-08 3 views
0

타일 통합을 사용하여 Struts2 f/w를 배우려고하지만 putAttributeTag에서 NPE를 구현 중입니다.타일을 호출 할 때 putAttribute의 NPE

로그인을 클릭하면 홈 페이지로 이동해야하지만 홈 페이지를 여는 동안 예외가 발생합니다.

다음은 관련 코드 중 일부입니다.

struts.xml

<package name="default" extends="struts-default" namespace="/"> 
    <result-types> 
     <result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/> 
     <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"></result-type> 
    </result-types> 


    <action name="signin" class="actions.SigninAction" method="execute"> 
     <result name="success" type="tiles">home</result> 
    </action> 

</package> 

tiles.xml

<tiles-definitions> 
    <definition name="baseLayout" template="/baseLayout.jsp"> 
     <put-attribute name="title" value=""></put-attribute> 
     <put-attribute name="header" value="/header.jsp"></put-attribute> 
     <put-attribute name="leftmenu" value="/leftmenu.jsp"></put-attribute> 
     <put-attribute name="footer" value="/footer.jsp"></put-attribute> 
     <put-attribute name="rightmenu" value="/rightmenu.jsp"></put-attribute> 
     <put-attribute name="content" value=""></put-attribute> 
    </definition> 

    <definition name="home" extends="baseLayout"> 
     <put-attribute name="content" value="/home.jsp"></put-attribute> 
     <put-attribute name="title" value="Home"></put-attribute> 
    </definition> 
</tiles-definitions> 

기본 레이아웃에 (템플릿의 다른 부분에 대한 다른 div의도 정의되어 있지만,이 난 것입니다 필요하다면 내가, 여기에 포함되지 않은 업데이트 baselayout)

<title><tiles:insertAttribute name="title" ignore="true"></tiles:insertAttribute> 
</title> 
</head> 
<body> 
     <div id="leftmenu" class=".leftmenu"> 
      <b>Add New</b><br> Update<br> Search<br> Remove 
     </div> 

     <div id="content" class=".content"> 
      <tiles:putAttribute name="content"></tiles:putAttribute> 
     </div> 

에는 간단한 한 줄 tex t 만. actions.SigninActionsuccess 만 반환합니다 (입력 유효성 검사는 아직 통합되지 않았습니다.이 액션도 성공을 반환합니다).

로그

메시지 :

ServletException including path '/baseLayout.jsp'. 
ServletException including path '/baseLayout.jsp'. 

스택 트레이스

org.apache.tiles.TilesException: ServletException including path '/baseLayout.jsp'. 
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:614) 
    org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:246) 
    org.apache.struts2.views.tiles.TilesResult.doExecute(TilesResult.java:105) 

org.apache.tiles.util.TilesIOException: ServletException including path '/baseLayout.jsp'. 
    org.apache.tiles.servlet.context.ServletTilesRequestContext.wrapServletException(ServletTilesRequestContext.java:298) 
    org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:200) 
    org.apache.tiles.servlet.context.ServletTilesRequestContext.dispatch(ServletTilesRequestContext.java:179) 
    org.apache.tiles.context.TilesRequestContextWrapper.dispatch(TilesRequestContextWrapper.java:72) 

java.lang.NullPointerException 
    org.apache.tiles.jsp.taglib.PutAttributeTag.execute(PutAttributeTag.java:204) 
    org.apache.tiles.jsp.taglib.RoleSecurityTagSupport.doEndTag(RoleSecurityTagSupport.java:75) 
    org.apache.jsp.baseLayout_jsp._jspx_meth_tiles_005fputAttribute_005f0(baseLayout_jsp.java:188) 
    org.apache.jsp.baseLayout_jsp._jspService(baseLayout_jsp.java:129) 

내 실수를 지적하면 좋을 것입니다.

+0

몇 가지 사항을 변경하여 문제를 해결했습니다. 내가 겪었던 n 개의 실수가있었습니다. – guptakvgaurav

답변

1

NPE의 이유는 baseLayoutinsertAttribute 대신 putAttribute 태그를 사용했기 때문입니다. 이 putAttribute 평가했을 때

<div id="content" class=".content"> 
    <tiles:putAttribute name="content"></tiles:putAttribute> 
</div> 

후, value 매개 변수가 누락했다. 따라서 NPE를 던지게됩니다.

수정 : insertAttribute 태그를 사용하여 값을 가져 와서 baselayout에 삽입합니다. 캐피탈 문자와 JSP로의 시작의

  1. 이름을 다음과 같이

    또한 내가 this blog 불구하고가는 후 변경 다른 것입니다.

  2. 타일 정의에서 다른보기 기술의 타일 정의에 대한 마커로 .tiles이 사용됩니다.
  3. 또한 타일 정의 이름 앞에 슬래시 /이 포함되며 그에 따라 struts.xml이 조정됩니다.
관련 문제