'소스 분석'에 해당되는 글 6건
- 2010.01.11 Spring 소스 분석 - View로 Model이 전달되는 방법
- 2009.08.27 O 프로그램 구조 분석
- 2009.07.24 SchemaSpy 실행시 charset 지정하기 2
- 2009.06.10 JPetStore 분석 2 - iBatis
- 2009.06.10 JPetStore 분석 1 - iBatis
- 2009.06.10 JPetStore 설치 - iBatis
- Spring 소스 분석 - View로 Model이 전달되는 방법
- 日常茶飯事
- 2010. 1. 11. 04:57
- Controller에서 ModelAndView를 리턴하는데 View에 전달되는 데이터는 어떤 식으로 저장되는지 궁금함.
DispatcherServlet
doService()
doDispatch()
render()
AbstractView
render()
renderMergedOutputModel()
InternalResourceView //여러 구현체중 하나
renderMergedOutputModel()
exposeModelAsRequestAttributes()
AbstractView
exposeModelAsRequestAttributes()
String modelName = (String) entry.getKey();
Object modelValue = entry.getValue();
if (modelValue != null) {
request.setAttribute(modelName, modelValue); //모델이름으로 request에 저장된다.
...
RequestDispatcher.include() - OR - forward()
doService()
doDispatch()
render()
AbstractView
render()
renderMergedOutputModel()
InternalResourceView //여러 구현체중 하나
renderMergedOutputModel()
exposeModelAsRequestAttributes()
AbstractView
exposeModelAsRequestAttributes()
String modelName = (String) entry.getKey();
Object modelValue = entry.getValue();
if (modelValue != null) {
request.setAttribute(modelName, modelValue); //모델이름으로 request에 저장된다.
...
RequestDispatcher.include() - OR - forward()
- O 프로그램 구조 분석
- 日常茶飯事
- 2009. 8. 27. 20:37
- do라는 확장자를 가진 요청이 들어오면 스트러츠(Struts2)에서 처리한다.
struts-xxx.xml
- 스트러츠 액션에서 서비스를 호출해서 사용하면 되는데 우리쪽에서는 모델1 방식이라서 jsp 를 직접 호출하게 되어 있다.
jsp 에서 서비스를 호출하는데 do라는 확장만 호출하게 되어 있는 구조라서 액션에서 편법을 사용했다. 1
그런데 BaseAction 에 페이징관련 메서드가 있는 이유를 모르겠다.
- DAO는 iBatis를 사용
예외처리가 세련되지 못함.
struts-xxx.xml
<action name="xxx_list" class="xxx.action.XxxAction" method="findList"> <result>/jsp/xxx/list.jsp</result> </action>xxx_list 라는 요청이 들어오면 xxx.action.XxxAction.findList() 가 호출되면 /jsp/xxx/list.jsp 로 이동하게 된다.
- 스트러츠 액션에서 서비스를 호출해서 사용하면 되는데 우리쪽에서는 모델1 방식이라서 jsp 를 직접 호출하게 되어 있다.
jsp 에서 서비스를 호출하는데 do라는 확장만 호출하게 되어 있는 구조라서 액션에서 편법을 사용했다. 1
public class XxxAction extends BaseAction(ActionSupport){ ... public String findList() throws Exception { return SUCCESS; } }/jsp/xxx/list.jsp 로 이동해서 서비스를 호출해서 데이터를 처리하는 방식을 사용했다.
그런데 BaseAction 에 페이징관련 메서드가 있는 이유를 모르겠다.
- DAO는 iBatis를 사용
예외처리가 세련되지 못함.
public class XxxServiceImpl implements XxxService{ private static XxxServiceImpl instance = new XxxServiceImpl(); public static XxxServiceImpl getInstance(){ return instance; } DaoManager daoManager = null; XxxDAO dao; private XxxServiceImpl(){ daoManager = DaoConfig.getDaoManager(); dao = (XxxDAO)daoManager.getDao(XxxDAO.class); } public List findList() throws Exception{ //Exception 을 안던지게 하도록 List list = null; try{ list = dao.getList(); } catch (DaoException de) { //여긴 없어도 될듯 log.error(de, de); throw de; } catch (Exception e) { log.error(e, e); throw e; } return list; } public int insert(XxxVO vo) throws Exception{ //음... int result = 1; try{ dao.insert(vo); //트랜잭션 처리를 하지 않아도 예외가 발생하면 Rollback된다. } catch (DaoException de) { result = 0; System.out.println("de="+de.toString()); } catch (Exception e) { result = 0; System.out.println("e="+e.toString()); } return result; } public String change(XxxVO vo, String state) throws Exception{ String err_msg = "FAIL"; try{ daoMgr.startTransaction(); //명시적인 트랜잭션 처리 err_msg = dao.update(vo); dao.insertState(vo, state); daoMgr.commitTransaction(); } catch (DaoException de) { log.error(de, de); throw de; } catch (Exception e) { log.error(e, e); throw e; }finally{ daoMgr.endTransaction(); } return err_msg; } ... }
public class XxxDAOImpl extends SqlMapDaoTemplate implements XxxDAO{ public XxxDAOImpl(DaoManager daoManager) { super(daoManager); } public List getList() throws DaoException{ //DaoException은 Runtime Exception이다. return (XxxVO) queryForObject("xxx.list"); } ... }- 일부 Ajax도 사용
- 그런데 jsp 에서 직접 서비스를 호출하는 것을 액션에서 처리하도록 수정하는데 얼마 안걸렸을거 같다. [본문으로]
- SchemaSpy 실행시 charset 지정하기
- 日常茶飯事
- 2009. 7. 24. 11:18
SchemaSpy로 생성되는 HTML파일은 charset이 ISO-8859-1이어서 한글이 깨진다.
실행인자를 설명한 표에는 인코딩에 관련된 내용은 없다.
Ant로 처리해야 하나?
오늘 다시 SchemaSpy(4.1.1)를 살펴보다가 소스를 살펴봤다. 1
- net.sourceforge.schemaspy.view.HtmlFormatter.java
- net.sourceforge.schemaspy.Config.java
이럴수가....문서화되지 않은 인자가 더 많은거 같다.
실행인자를 설명한 표에는 인코딩에 관련된 내용은 없다.
Ant로 처리해야 하나?
오늘 다시 SchemaSpy(4.1.1)를 살펴보다가 소스를 살펴봤다. 1
- net.sourceforge.schemaspy.view.HtmlFormatter.java
out.writeln(" <meta HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=" + Config.getInstance().getCharset() + "'>"); out.writeln(" <SCRIPT LANGUAGE='JavaScript' TYPE='text/javascript' SRC='" + (table == null ? "" : "../") + "jquery.js'></SCRIPT>");
- net.sourceforge.schemaspy.Config.java
public String getCharset() { if (charset == null) { charset = pullParam("-charset"); if (charset == null) charset = "ISO-8859-1"; } return charset; }
이럴수가....문서화되지 않은 인자가 더 많은거 같다.
- 2009-07-24 [본문으로]
- JPetStore 분석 2 - iBatis
- 日常茶飯事
- 2009. 6. 10. 23:09
Product ID가 빠졌다.
catalog/Product.jsp
13번째 라인에서 item#productId 임.
1. item 을 product 로 변경한다.
Item.xml
product#productId 에는 들어가는데 item#productId 에는 들어가지 않는다.
2. 쿼리에 productId 를 추가한다.
iBatis에서 주석은 -- 대신 /* */ 를 사용할 것.
catalog/Product.jsp
13번째 라인에서 item#productId 임.
1. item 을 product 로 변경한다.
<div id="Catalog"> <h2><bean:write name="product" property="name"/></h2> <table> <tr><th>Item ID</th> <th>Product ID</th> <th>Description</th> <th>List Price</th> <th> </th></tr> <logic:iterate id="item" name="itemList"> <tr> <td> <html:link paramId="itemId" paramName="item" paramProperty="itemId" page="/shop/viewItem.shtml"> <bean:write name="item" property="itemId"/></html:link></td> <td><bean:write name="item" property="productId"/></td> <td> <bean:write name="item" property="attribute1"/> <bean:write name="item" property="attribute2"/> <bean:write name="item" property="attribute3"/> <bean:write name="item" property="attribute4"/> <bean:write name="item" property="attribute5"/> <bean:write name="product" property="name"/> </td> <td><bean:write name="item" property="listPrice" format="$#,##0.00"/></td> <td><html:link styleClass="Button" paramId="workingItemId" paramName="item" paramProperty="itemId" page="/shop/addItemToCart.shtml"> Add to Cart</html:link></td> </tr> </logic:iterate> <tr><td> <logic:notEqual name="itemList" property="firstPage" value="true"> <a class="Button" href="switchItemListPage.shtml?pageDirection=previous"><< Prev</a> </logic:notEqual> <logic:notEqual name="itemList" property="lastPage" value="true"> <a class="Button" href="switchItemListPage.shtml?pageDirection=next">Next >></a> </logic:notEqual> </td></tr> </table> </div>
Item.xml
product#productId 에는 들어가는데 item#productId 에는 들어가지 않는다.
2. 쿼리에 productId 를 추가한다.
<select id="getItemListByProduct" resultClass="item" parameterClass="string" cacheModel="itemCache"> SELECT ITEMID, LISTPRICE, UNITCOST, SUPPLIER AS supplierId, I.PRODUCTID AS "product.productId", /* I.PRODUCTID, */ NAME AS "product.name", DESCN AS "product.description", CATEGORY AS "product.categoryId", STATUS, ATTR1 AS attribute1, ATTR2 AS attribute2, ATTR3 AS attribute3, ATTR4 AS attribute4, ATTR5 AS attribute5 FROM ITEM I, PRODUCT P WHERE P.PRODUCTID = I.PRODUCTID AND I.PRODUCTID = #value# </select>
iBatis에서 주석은 -- 대신 /* */ 를 사용할 것.
- JPetStore 분석 1 - iBatis
- 日常茶飯事
- 2009. 6. 10. 17:03
- JPetStore 5.0 Example Application
Struts 1.2, beanaction.jar(23,198 bytes)
iBatis 2
- web.xml
- /shop/index.shtml
org.apache.struts.beanaction.BeanAction
name=catalogBean
parameter="*"
/catalog/Main.jsp
- /shop/viewCategory.shtml?categoryId=FISH
org.apache.struts.beanaction.BeanAction
name=catalogBean
catalogBean#viewCategory() //비지니스 메서드 호출
/catalog/Category.jsp
parameter 설정이 없으면 path 에서 마지막 경로에 해당하는 메서드 호출
단, parameter가 *이면 어떤 메서드도 호출 안됨.
- 아래와 같이 특정 확장자에 대한 매핑이 가능
Struts 1.2, beanaction.jar(23,198 bytes)
iBatis 2
- web.xml
- *.shtml 는 Struts action에서 처리하도록 함.
- security-constraint 로 jsp파일을 직접 호출하지 못하게 함.
<security-constraint> <web-resource-collection> <web-resource-name>Restrict access to JSP pages</web-resource-name> <url-pattern>*.jsp</url-pattern> </web-resource-collection> <auth-constraint> <description>With no roles defined, no access granted</description> </auth-constraint> </security-constraint>
- /shop/index.shtml
org.apache.struts.beanaction.BeanAction
name=catalogBean
parameter="*"
/catalog/Main.jsp
<%@ include file="../common/IncludeTop.jsp" %> 내용 <%@ include file="../common/IncludeBottom.jsp" %>
- /shop/viewCategory.shtml?categoryId=FISH
org.apache.struts.beanaction.BeanAction
name=catalogBean
catalogBean#viewCategory() //비지니스 메서드 호출
/catalog/Category.jsp
<bean:define id="category" name="catalogBean" property="category"/> <bean:define id="productList" name="catalogBean" property="productList"/> <logic:iterate id="product" name="productList"> <tr> <td> <html:link paramId="productId" paramName="product" paramProperty="productId" page="/shop/viewProduct.shtml"> <bean:write name="product" property="productId"/> </html:link> </td> <td><bean:write name="product" property="name"/></td> </tr> </logic:iterate>- BeanAction에서는 parameter 설정이 있으면 name의 해당 메서드 호출
parameter 설정이 없으면 path 에서 마지막 경로에 해당하는 메서드 호출
단, parameter가 *이면 어떤 메서드도 호출 안됨.
- 아래와 같이 특정 확장자에 대한 매핑이 가능
<action path="/test.elf" type="org.apache.struts.beanaction.BeanAction" name="catalogBean" parameter="*" validate="false"> <forward name="success" path="/t.jsp"/> </action>
- JPetStore 설치 - iBatis
- 日常茶飯事
- 2009. 6. 10. 00:35
- JPetStore-5.0/build/wars/jpetstore.war 로 배포할 수 있다.
또는
- Eclipse에서 구동시키기
- 기본 설정이 hsqldb로 되어 있으므로 추가적인 설정이나 데이터베이스 없이 바로 구동할 수 있다.
- 다른 데이터베이스로 변경하는 경우에는
또는
- Eclipse에서 구동시키기
- Dynamic Web Project 를 생성한다.
- Import
src : JavaSource
web : WebContent
lib : WebContent/WEB-INF/lib
- 기본 설정이 hsqldb로 되어 있으므로 추가적인 설정이나 데이터베이스 없이 바로 구동할 수 있다.
- 다른 데이터베이스로 변경하는 경우에는
- JPetStore-5.0/src/ddl/ 의 스크립트를 사용하여 테이블을 생성하고 데이터를 입력한다.
- WEB-INF/classes/properties/database.properties 를 설정한다.
- Item.xml에서 getItem의 쿼리를 수정한다. : itemid 가 명확하지 않아 에러가 발생하므로 v.ITEMID로 변경한다.
Recent comment