'2008/Spring 2.5'에 해당되는 글 6건
- 2008.10.30 JEUS 4.2설정
- 2008.09.20 5교시 DBConnection
- 2008.09.20 4교시 SpringFramework 설정
- 2008.09.20 3교시_2 톰켓 설정
- 2008.09.20 첫번째 3번째 시간
- 2008.09.20 spring 1차 수업
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- the test application context definition for the jdbc based tests -->
<bean id="productDao" class="springapp.repository.JdbcProductDao">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
</beans>
=================================
Document path
C:\spring\util\apache-tomcat-5.5.27\webapps\tomcat-docs\index.html
8) JNDI Resources
4. Configure Tomcat's Resource Factory
To configure Tomcat's resource factory, add an elements like this to the $CATALINA_HOME/conf/server.xml
file, nested inside the Context
element for this web application.
![]() |
![]() |
![]() |
![]() |
<Context ...> ... <Resource name="bean/MyBeanFactory" auth="Container" type="com.mycompany.MyBean" factory="com.mycompany.MyBeanFactory" bar="23"/> ... </Context> |
![]() |
![]() |
![]() |
![]() |
Note that the resource name (here, bean/MyBeanFactory
must match the value specified in the web application deployment descriptor. We are also initializing the value of the bar
property, which will cause setBar(23)
to be called before the new bean is returned. Because we are not initializing the foo
property (although we could have), the bean will contain whatever default value is set up by its constructor.
tomcat Server.xml 설정
<GlobalNamingResources>
<Resource name="jdbc/SpringDB" auth="Container"
type="javax.sql.DataSource" username="spring" password="spring123"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:XE"
maxActive="8" maxIdle="4"/>
</GlobalNamingResources>
맨밑에
<Context docBase="spring_1"
path="/spring_1"
reloadable="true"
source="org.eclipse.jst.j2ee.server:spring_1">
<ResourceLink name="jdbc/SpringDB"
global="jdbc/SpringDB"
type="javax.sql.DataSource"/>
</Context>
설정 하고 나서 Test_jndi.jsp 만들어서 Test를 해봅시다.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<%@ page import="javax.naming.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<% InitialContext ctx = new InitialContext();
Object obj = ctx.lookup("java:comp/env/jdbc/SpringDB");
if(obj != null)
{
javax.sql.DataSource ds = (javax.sql.DataSource)obj;
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM BOARD ";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
out.println(rs.getString(1) + "<br>");
}
stmt.close();
conn.close();
}
else {
out.println("검색 실패 !!");
}
%>
</body>
</html>
http://static.springframework.org/docs/Spring-MVC-step-by-step/part1.html
web.xml 추가
<servlet>
<servlet-name>springapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springapp</servlet-name>
<url-pattern>*.htm</url-pattern> -> *.do로 수정
</servlet-mapping>
2.
C:\spring\util\spring-framework-2.5.5\dist
(1.7 step by step)
spring.jar
spring-webmvc.jar 드레그 해서 이클립스 Webcontent/WEB-INF/lib/에 넣는다.
--------------------
springapp-servlet.xml <-- 이름으로 하나 만든다.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- the application context definition for the springapp DispatcherServlet -->
<bean name="/hello.htm" class="springapp.web.HelloController"/>
</beans>
<bean name="/hello.htm" class="springapp.web.HelloController"/> 요청 Url
<bean id=""> ID 공유할때는 ID ; 특스문자 사용 불가
<!-- http://localhost:8088/spring_1/hello.do -->
<bean name="/hello.do" class="springapp.web.HelloController"/>
=======================================
1. springapp-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- the application context definition for the springapp DispatcherServlet -->
<!-- http://localhost:8088/spring_1/hello.do -->
<bean name="/hello.do" class="springapp.web.HelloController"/>
//springapp.web.HelloController를 /hello.do로 매핑 합니다.
</beans>
2. HelloController.java class 만들기
package springapp.web;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
import java.io.IOException;
public class HelloController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws Exception
{
ModelAndView mv = new ModelAndView();
mv.setViewName("spring_hello.jsp");
mv.addObject("greeting","첫번째 스프링 예제!!!");
return mv;
}
}
3. jsp Page만들기
spring_hello.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
${greeting}
</body>
</html>
4. index.htm
<html>
<head>
<script type="text/javascript">
<!--
location.href="hello.do";
-->
</script>
</head>
<body>
</body>
</html>
----------- 그러면 나온다 ; 아 힘드네 ㅋㅋ
1일차
1.apache
http://apache.org/
(http://tomcat.apache.org/)
2. Eclipse 다운로드
http://eclipse.org
3. 스프링 프레임워크
http://springframework.org/download
(http://sourceforge.net/project/showfiles.php?group_id=73357&package_id=173644&release_id=608794)
4. Oracle
http://oracle.com
C:Spring 폴더 생성
util안에 1)apache-tomcat-5.5.27
2)eclipse-SDK-3.3.2-win32
3)spring-framework-2.5.5-with-docs
4)OracleXEUniv.exe
필요 합니다.
설치..
오라클 설치후