티스토리 툴바


1. xml 문서에서 context:annotation-config를 통해서 직접적으로 연결하지 않고, Autowired를 사용할 수 있게 해준다.

2. 따라서 java class에서 @Autowired를 사용했다.

3. 하지만, 1번 xml 문서의 14라인의 새로운 이름의 MessageBean에 대한 bean이 존재하게 될 경우 아래와 같은 에러가 발생하게 된다.

2009. 8. 13 오후 5:44:54 org.springframework.context.support.AbstractApplicationContext prepareRefresh
정보: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@15eb0a9: display name [org.springframework.context.support.FileSystemXmlApplicationContext@15eb0a9]; startup date [Thu Aug 13 17:44:54 KST 2009]; root of context hierarchy
2009. 8. 13 오후 5:44:54 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
정보: Loading XML bean definitions from file [C:\JSP\Spring\src\newanno\newaano.xml]
2009. 8. 13 오후 5:44:54 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
정보: Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@15eb0a9]: org.springframework.beans.factory.support.DefaultListableBeanFactory@111a775
2009. 8. 13 오후 5:44:54 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
정보: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@111a775: defining beans [org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,new,message,message2]; root of factory hierarchy
2009. 8. 13 오후 5:44:54 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
정보: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@111a775: defining beans [org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,new,message,message2]; root of factory hierarchy
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'new': Autowiring of methods failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void newanno.NewAnnoImp.setBean(newanno.MessageBean); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [newanno.MessageBean] is defined: expected single matching bean but found 2: [message, message2]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:256)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:998)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
    at newanno.AnnoTest.main(AnnoTest.java:9)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void newanno.NewAnnoImp.setBean(newanno.MessageBean); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [newanno.MessageBean] is defined: expected single matching bean but found 2: [message, message2]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)
    at org.springframework.beans.factory.annotation.InjectionMetadata.injectMethods(InjectionMetadata.java:117)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:253)
    ... 16 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [newanno.MessageBean] is defined: expected single matching bean but found 2: [message, message2]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:621)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:499)
    ... 18 more


4.여기에 대한 해결 방법은 @Qualifier 이다.
xml문서의 bean들에 qualifier value값을 정의하고, class파일에서 해당 value 값을 적어 줌으로써 원하는 bean을 참조할 수 있다.


5. 응용

더보기



※ 참고사이트
http://homo-ware.tistory.com/13
@Autowired
@Autowired annotation은 아래 예제처럼 전형적인 setter 메소드에 적용될 수 있다.
public class SimpleMovieLister {
   private MovieFinder movieFinder;
   @Autowired
   public void setMovieFinder(MovieFinder movieFinder) {
      this.moveFinder = movieFinder;
   }
   // ...
}

이 annotation은 또한 임의의 이름이나 인자를 여러개 있는 메소드에서도 적용될 수 있다.
public class MovieRecommender {
   private MovieCatalog movieCatalog;
   private CustomerPreferenceDao customerPreferenceDao;
   @Autowired
   public void prepare(MovieCatalog movieCatalog,
         CustomerPreferenceDao customerPreferenceDao) {
      this.movieCatalog = movieCatalog;
      this.customerPreferenceDao = customerPreferenceDao;
   }
   // ...
}

@Autowired annotation은 심지어 생성자나 필드에도 적용될 수 있다.
public class MovieRecommender {
   @Autowired
   private MovieCatalog movieCatalog;
   private CustomerPreferenceDao customerPreferenceDao;
   @Autowired
   public MovieRecommender(CustomerPreferenceDao customerPreferenceDao) {
      this.customerPreferenceDao = customerPreferenceDao;
   }
   // ...
}

또한 해당 타입이 배열인 필드나 메소드에 annotation을 추가하여 ApplicationContext로부터 특정 타입의 모든 빈들을 제공하는 것이 가능하다.
public class MovieRecommender {
   @Autowired
   private MovieCatalog[] movieCatalogs;
   // ...
}

만일 자바 5를 사용하고 있다면, 타입이 지정된 collection에 대해서 동일하게 적용된다.
public class MovieRecommender {
   private Set<MovieCatalog> movieCatalogs;
   @Autowired
   public void setMovieCatalogs(Set<MovieCatalog> movieCatalogs) {
      this.movieCatalogs = movieCatalogs;
   }
   // ...
}

심지어 Map 타입도 key 의 타입이 String인 경우에 자동으로 엮여질(autowired) 수 았다. Map의 value는 예상되는 타입의 모든 빈들을 포함하게 되며, key는 해당 bean의 이름들을 포함하게 된다.
public class MovieRecommender {
   private Map<String, MovieCatalog> movieCatalogs;
   @Autowired
   public void setMovieCatalogs(Map<String, MovieCatalog> movieCatalogs) {
      this.movieCatalogs = movieCatalogs;
   }
   // ...
}

기본적으로 자동 엮음(autowiring)은 가능한 빈드이 없다면 실패하게 된다. 기본적인 행위는 annotation이 있는 메소드, 생성자, 필드를 required 로 지정되어 있는 것으로 처리한다. 이러한 행위는 다음과 같이 변경이 가능하다.
public class SimpleMovieLister {
   private MovieFinder movieFinder;
   @Autowired(required=false)
   public void setMovieFinder(MovieFinder movieFinder) {
      this.moveFinder = movieFinder;
   }
   // ...
}

주의 - 클래스 당 오직 하나의 annotation이 있는 생성자만 required로 표기가 가능하며, 여러개의 필수가 아닌 생성자는 anootation이 가능하다. 이 경우, 각각은 주입이 가능한 빈들 사이에서 고려되어지며 Spring은 의존성이 만족될 수 있는 가장 필요한 생성자를 사용한다.

http://homo-ware.tistory.com/14
Qualifier를 사용하는 annotation 기반 자동엮음(autowiring) 세부 조정

타입에 의한 자동엮음(autowiring)은 여러개의 빈이 엮여질 수 있기 때문에 선택 과정에 대해서 좀 더 제어를 할 필요가 종종 있다. 이를 하기 위한 한가지 방법은 Spring의 @Qualifier annotation을 사용하는 것이다. 가장 단순한 경우, annotation 내의 빈 이름을 써서 byName 자동엮음을 할 수 있다.
public class MovieRecommender {
   @Autowired
   @Qualifier("mainCatalog")
   private MovieCatalog movieCatalog;
   // ...
}

@Qualifier annotation은 또한 개개의 생성자 인자나 메소드 파라미터에 지정이 가능하다.
public class MovieRecommender {
   private MovieCatalog movieCatalog;
   private CustomerPreferenceDao customerPreferenceDao;
   @Autowired
   public void prepare(@Qualifier("mainCatalog") MovieCatalog movieCatalog,
         CustomerPreferenceDao customerPreferenceDao) {
      this.movieCatalog = movieCatalog;
      this.customerPreferenceDao = customerPreferenceDao;
   }
   // ...
}

또한 사용자에 맞는 qualifier annotation을 만들 수도 있다. 단순하게 annotation을 정의하고 정의 내에 @Qualifier annotation을 쓰면 된다.
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface Genre {
   String value();
}
그 다음에 자동엮음을 하려는 필드와 파라미터에 만들어진 qualifier를 적용할 수 있다.
public class MovieRecommender {
   @Autowired
   @Genre("Action")
   private MovieCatalog actionCatalog;
   private MovieCatalog comedyCatalog;
   @Autowired
   public void setComedyCatalog(@Genre("Comedy")
         MovieCatalog comedyCatalog) {
      this.comedyCatalog = comedyCatalog;
   }
   // ...
}
다음 단계는 자동엮여질 후보 빈 정의에 해당 정보를 추가하는 것이다. <bean/> 태그의 하위 요소로 <qualifier/> 태그를 추가하고 나서 만들어진 qualifier annotation과 일치하는 'type'과 'value'를 지정한다. type은 annotation의 패키지를 포함한 전체 클래스명과 일치하거나, 이름이 충돌날 염려가 없는 경우에는 '짧은' 클래스명을 사용할 수 있다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-2.5.xsd">
   <context:annotation-config/>
   <bean class="example.SimpleMovieCatalog">
      <qualifier type="Genre" value="Action"/>
      <!-- inject any dependencies required by this bean -->
   </bean>
   <bean class="example.SimpleMovieCatalog">
      <qualifier type="example.Genre" value="Comedy"/>
      <!-- inject any dependencies required by this bean -->
   </bean>
   <bean id="movieRecommender" class="example.MovieRecommender"/>
</beans>

어떤 경우에는 value 없이 annotation을 사용하는 것으로 충분한 경우가 있다. 이는 annotation이 좀 더 일반적인 목적으로 사용되고 몇몇 다른 type의 의존성으로 적용될 때 유용하다. 예를 들어, 어떠한 인터넷 연결이 안되었을 때에 검색될 수 있는 offline 카탈로그를 제공할 수도 있다. 먼저 단순한 annotation을 다음과 같이 정의한다.
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface Offline {
}
그 다음에 자동엮여질 필드나 속성에 annotation을 추가한다.
public class MovieRecommender {
   @Autowired
   @Offline
   private MovieCatalog offlineCatalog;
   // ...
}
이제 빈 정의는 qualifier 'type' 만 필요하다.
<bean class="example.SimpleMovieCatalog">
   <qualifier type="Offline"/>
   <!-- inject any dependencies required by this bean -->
</bean>

추가로 혹은 단순한 'value' 속성 대신에 이름이 지정된 속성을 받아들이는 qualifier annotation을 정의할 수도 있다. 만일 여러개의 속성 값들이 자동엮여질 필드나 파라미터에 지정된다면 빈 정의는 자동엮음 대상이라고 생각되는 속성 값 모두와 일치해야 한다. 예를 들어, 다음과 같은 annotation 정의를 생각할 수 있다.
@Target({ElementType.FIELD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface MovieQualifier {
   String genre();
   Format format();
}
이 경우 Format은 다음과 같은 enum 이다.
public enum Format {
   VHS, DVD, BLURAY;
}
마지막으로 빈 정의는 qualifier 값들에 대한 일치하는 것을 포함해야 한다. 이 예제에서는 또한 bean의 meta 속성이 <qualifier/> 하위 요소 대신에 사용될 수 있음을 보여준다. 가능하다면, <qualifier/> 와 그 속성들이 우선시되지만, 자동엮음 메커니즘은 qualifier 가 존재하지 않는다면 <meta/> 태그 내에서 제공되는 값을 대신 사용하게 된다. (마지막 2개의 빈 정의 참조)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context-2.5.xsd">
   <context:annotation-config/>
   <bean class="example.SimpleMovieCatalog">
      <qualifier type="MovieQualifier">
         <attribute name="format" value="VHS"/>
         <attribute name="genre" value="Action"/>
      </qualifier>
      <!-- inject any dependencies required by this bean -->
   </bean>
   <bean class="example.SimpleMovieCatalog">
      <qualifier type="MovieQualifier">
         <attribute name="format" value="VHS"/>
         <attribute name="genre" value="Comedy"/>
      </qualifier>
      <!-- inject any dependencies required by this bean -->
   <bean>
   <bean class="example.SimpleMovieCatalog">
      <meta key="format" value="DVD"/>
      <meta key="genre" value="Action"/>
      <!-- inject any dependencies required by this bean -->
    <bean>
    <bean class="example.SimpleMovieCatalog">
      <meta key="format" value="BLURAY"/>
      <meta key="genre" value="Comedy"/>
      <!-- inject any dependencies required by this bean -->
    <bean>
</beans>


저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드
  • @Required annotation을 사용하면서 해당 필드나 메소드에 값을 넣어주지 않았기 때문이다.
  • 따라서, XML 문서에서 p태그 또는 property 태그를 이용해서 속성 값을 넣어주어야 한다.





Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'annotation' defined in file [C:\JSP\Spring\src\annotation2\annotation.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Property 'message' is required for bean 'annotation'

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
    at annotation2.AnnoTest.main(AnnoTest.java:9)
Caused by: org.springframework.beans.factory.BeanInitializationException: Property 'message' is required for bean 'annotation'
    at org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.postProcessPropertyValues(RequiredAnnotationBeanPostProcessor.java:121)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:998)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    ... 14 more
저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드
JavaAPI의 Iterator에서....
Method Summary
 boolean hasNext()
          Returns true if the iteration has more elements.
 E next()
          Returns the next element in the iteration.
 void remove()
          Removes from the underlying collection the last element returned by the iterator (optional operation).
 

Method Detail

hasNext

boolean hasNext()
Returns true if the iteration has more elements. (In other words, returns true if next would return an element rather than throwing an exception.)

Returns:
true if the iterator has more elements.



next

E next()
Returns the next element in the iteration.

Returns:
the next element in the iteration.
Throws:
NoSuchElementException - iteration has no more elements.




remove

void remove()
Removes from the underlying collection the last element returned by the iterator (optional operation). This method can be called only once per call to next. The behavior of an iterator is unspecified if the underlying collection is modified while the iteration is in progress in any way other than by calling this method.

Throws:
UnsupportedOperationException - if the remove operation is not supported by this Iterator.
IllegalStateException - if the next method has not yet been called, or the remove method has already been called after the last call to the next method.




  • hasNext()의 리턴값은 boolean이다. 즉, Iterator의 다음 원소가 존재하는지를 반환해 줌으로써 while(i.hasNext()) 와 같은 반복문에서 조건절에 넣어준다.
  • next()는 Iterator의 다음 원소(element)를 반환해 준다.

저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드

저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드
org.apache.struts.chain.commands.InvalidPathException: No action config found for the specified url.

이 에러는 soure에서 path를 잘 못 설정해 줬을 때 발생했다.

Action관련 파일에서 path를 다시 확인하자.

자바에서 *.do 를 해 줄 때는 경로가 필요없다.
(예 : return new ActionForward("/productList.do", true); )

그리고 *.jsp 는 경로를 적어준다.
(예 : return new ActionForward("/product/cartList.jsp", false); )


저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드
1. iBatis를 사용해서 DB에 데이터를 저장하기 위해 관련 library를 WebContent\WEB-INF\lib 에 복사해 넣는다.
 
2. SQL Map XML을 설정하기 위해서 iBatis 개발자 노트를 참고한다.
     2-1) properties resource 태그를 복사

     2-2) 아래와 같이 src\dao\SqlMapConfig.xml 에 추가한다.

    2-3)
settings 태그 부분도 복사하고,

      2-4)
동일 문서에서 추출 한 transactionManager 태그 부분도 SqlMapConfig.xml 에 추가한다.

기존의 태그가 있다면 새롭게 작성을 한다.


     2-5) 2-2)에서 작성한 코드, properties resource의 정의된 파일을 생성한다.

경로

해당 폴더에서 File을 만든다. 확장자는 properties


     2-6) 해당 파일의 내용에 driver, url, username, password를 작성한다.
이 속성명은 2-4)의 tranjaction manager의 property들의 value와 같아야 한다.


3. dao\TestDAO 클래스 생성

4. util\ServiceUtil 클래스 생성
이 클래스의 getSqlMapper()에서 반환하는 값을 계속 이용할 것이다.
Model2에서 getCon() 과 동일한 역활을 한다.

5. test 성격의 테이블 생성. PK의 NO는 SEQ를 이용.

6. SqlMapConfig에서 sqlMap을 ibx.xml로 정의했다. 해당 파일의 코드.
게시판에 글을 작성하고 DB에 넣기 위해, 먼저 insert query를 작성했다.

7. struts-config.xml에서 action을 정의한다.

8. 실제 action이 처리 될 StrutsInsertAction 클래스 생성.
Action을 is-a 상속 받고 insert 작업이 성공되는지 console에 결과값을 출력하는 방법을 통해서 확인한다.(int값을 return하기 때문에 insert에 성공한 entity 수를 알 수 있다.)

9. 예를 보자.

10. 500 error가 발생했다.

11. 이유와 해결 방법은 다음과 같다.

12. 성공적으로 페이지 처리가 됨을 알 수 있다.

13. ListAction 클래스에서 DB에 저장 된 데이터를 불러오는 지 확인한다.

14. TestDAO class의 selectALL() 메소드는 sall이라는 id의 쿼리를 결과를 return한다.

15. sall의 id를 가지는 쿼리는 ibx.xml에 작성한다.
이 때 resultMap 태그의 id와 sall 쿼리의 resultMap의 값은 동일하게 한다.
[조심] 그리고 select 쿼리의 결과로 나오는 컬럼들에 대해서 동일한 수와 이름의 result property를 만든다.

16. 실행 결과 (HIT 컬럼은 추가적인 작업으로 작성했음.)
ID에 링크를 연결해서 작성한 글의 세부 내용을 볼 수 있는 info.jsp를 생성한다.
info.jsp로 이동하기 위해 HitAction class에서 조회수를 1 증가 시켜주는 이벤트를 실행하고, InfoAction에서 해당 글의 no를 바탕으로 내용을 조회한다. (코드생략)
저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드
1.http://upperbound.tistory.com/entry/090729WEN-STRUTS-%EC%84%A4%EC%A0%95 에서 작성했던 strutsform.jsp의 form action 값을 수정한다.

2. struts-config.xml에서 action-mappings에 새로운 action을 추가한다.

3. 앞서 설정한 action의 type에 맞는 새로운 StrutsInsertAction 을 만들어 준다. 이 방법을 통해서 다시금 result.jsp 페이지로 이동 할 수 있다.

4. 이제 2번의 action을 수정해보자. action에서 forward를 해 주기 때문에 StrutsInsertAction에서 forward 될 목적 경로를 작성하지 않아도 된다. 대신에 forward name을 return 해서 forward 경로를 선택할 수 있게 StrutsInsertAction의 return을 수정한다.


5. <form-beans> 안에는 복수의 <form-bean>이 들어갈 수 있다.
여기서 작성해준


6.

7. 윗 소스대로 작성하면 에러가 발생한다. 이유는 action에서는 iBatisStruts라는 상위 폴더 명을 적지 않고 바로 이동할 페이지 주소를 적어주어야 에러가 발생하지 않기 때문이다.
저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드
1.apache.org에서 STRUTS를 찾아간다.

2. STRUTS는 1버젼과 2버젼 두 종류가 있다. 우선은 1의 최신 버젼 1.3.10을 다운 받자.
연습을 위해서 Examples를 선택.

3. 다운 받은 압축 파일을 풀어 보면 apps 폴더에 struts-blank-1.3.10.war 파일이 있다.
이 파일은 연습용으로 사용하기 적당한 비어 있는 형식이므로 참고해서 struts를 익혀보자.

4. 해당 폴더의 WEB-INF 폴더에서 web.xml을 제외한 두 개의 xml 파일을 복사한 후, eclipse의 Dynamic Web Project로 생성한 workspace의 WEB-INF에 붙여넣기 한다.

5. WEB-INF\lib 에 있는 jar 파일들도 모두 복사한 후, workspace의 동일 경로에 저장한다.

6. 동일 파일들을 Tomcat의 common\lib 에도 붙여넣기 한다.

7. eclpise에서 확인 가능.

8. 이제 test를 위한 jsp 페이지를 만들자.

9. test를 위한 login 페이지를 만들고 form action을 "/logininsert.do"로 작성한다.

※ 아래와 같이 action의 경로에 프로젝트 명을 추가해줘야 한다.

10.

11. 당연히 404 error가 발생한다.

12. 앞서서 압축을 풀었던 struts-blank-1.3.10의 web.xml에서 <init-param> 부분을 복사한다.

13. 12번의 내용을 workspace의 WEB-INF\web.xml의 <servlet> 태그 사이에 붙여넣기 한다.


14. WEB-INF\struts-config.xml 은 path를 바탕으로 forward 시키는 약속을 정의하는 문서이다.
우리가 작성한 logininsert를 새로운 action path로 설정하고 임의의 페이지로 forward 하자.

15. 아래와 같이 성공적으로 forward 되었다. 이제 struts를 즐겨보자.



16. forward를 하는 또 다른 방법.
1) action type을 선언한다.
2) 해당하는 class파일을 생성한다.
3) 2)에서 생성한 class 파일이 return하는 파라미터 값이 1)에서 선언한 name과 동일한 경우 해당 name으로 연결한 path로 이동이 일어난다.
이를 응용하면 action을 처리할 때, 성공과 실패 시 각 상황별 페이징 처리가 용이할 것 같다.


저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드
FROM : http://www.hoonyy.com/bbs/board.php?bo_table=dev&wr_id=22&sca=oracle

1. 현재 시퀀스 확인

SELECT 어쩌구_SEQ.CURRVAL

FROM DUAL;

 

<참고>

처음부터 CURRVAL 확인하려고 한다면 다음과 같은 메시지를 확인할 수 있다;;

ORA-08002: 시퀀스 어쩌구_SEQ.CURRVAL은 이 세션에서는 정의 되어있지않습니다.

CURRVAL은 NEXTVAL을 사용한 후에야, 같은 세션 동안에서만 사용 가능하다.

 

그냥 단지;;; 마지막 시퀀스를 확인만 하고 싶은 것이라면 굳이 NEXTVAL 수행하지 않고

다음 쿼리만으로 확인 가능하다.

 

    SELECT *    -- LAST_NUMBER : 마지막 시퀀스

    FROM    USER_SEQUENCES

    WHERE  SEQUENCE_NAME = '어쩌구_SEQ';

 

 

2. 다음 시퀀스 확인

SELECT 테이블_SEQ.NEXTVAL

FROM DUAL;

 

<참고>

하나의 SQL 문에서 시퀀스를 사용할 때에는 여러 번 사용하여도 항상 동일한 값이 제공된다.

특히 CURRVAL과 NEXTVAL을 함께 사용할 때에는 그 순서와는 관계 없이 CURRVAL도 NEXTVAL의 값을 따라가게 된다.


 

SELECT 어쩌구_SEQ.CURRVAL, 어쩌구_SEQ.NEXTVAL

FROM    DUAL;

 

3. CURRVAL, NEXTVAL 사용할 수 있는 경우

  - subquery가 아닌 SELECT문
  - insert문의 SELECT절
  - insert문의 VALUE절
  - update문의 SET절
저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드

[자바스크립트] window.open 속성 사용 방법


<script type="text/javascript">

/*
window.open(url:String, name:String, properties:String)
open 함수는 반드시 3개의 매개변수가 있고, 매개변수 순서는 지켜야 함.
name은 팝업창의 이름, 주로 프레임 문서의 Target으로 사용
name은 사용하지 않으려면 " " 만 표시해줍니다. 반드시 표시해야 함.
*/


function win() {
window.open("http://eschyles.mireene.com/", "", ""); //속성 지정하지 않은 기본창
}


function menu_win() {
window.open("http://eschyles.mireene.com/", "", "menubar=1"); //메뉴바 없는 팝업
}


function full_win() {
window.open("http://eschyles.mireene.com/", "", "fullscreen"); //풀스크린 방식
}

function channel_win() {
window.open("http://eschyles.mireene.com/", "", "channelmode"); //채널모드

}


function status_win() { // 상태표시바 있는 팝업
window.open("http://eschyles.mireene.com/", "", "width=400, height=300, status=1");
}


function popup_win1() { //크기 width400 height300 팝업창
window.open("http://eschyles.mireene.com/", "", "width=400, height=300");
}


function popup_win2() { //위치 left=500, top=400 에서 열리는 팝업창
window.open("http://eschyles.mireene.com/", "", "width=400, height=300, left=500, top=400");
}


function popup_win3() { //스크롤바 있는 팝업
window.open("http://eschyles.mireene.com/", "", "width=400, height=300, scrollbars=1");
}


function popup_win4() { //주소표시줄 있는 팝업
window.open("http://eschyles.mireene.com/", "", "width=400, height=300, left=100, location=1");
}
</script>


<body>
<input type="button" value="속성 지정하지 않은 기본 창" onclick="win()">

<input type="button" value="메뉴바 없는 팝업" onclick="menu_win()">

<input type="button" value="풀스크린 팝업" onclick="full_win()">

<input type="button" value="채널모드 팝업" onclick="channel_win()">

<input type="button" value="상태표시바 있는 팝업" onclick="status_win()">

<input type="button" value="width400 height300 팝업창" onclick="popup_win1()">

<input type="button" value="위치 left=500, top=400 팝업창" onclick="popup_win2()">

<input type="button" value="스크롤바 있는 팝업" onclick="popup_win3()">

<input type="button" value="주소 입력 표시줄 있는 팝업" onclick="popup_win4()">

</body>

[출처] [자바스크립트] window.open 속성 사용 방법|작성자 스시대장

저작자 표시 비영리 동일 조건 변경 허락
크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by 어퍼바운드