jamin
Feb 10th, 2006, 09:37 AM
Hi,
Im tryng to learn spring and am implementing a e shop framework, i have all my service and data acess working but am having trouble with the web stuff.
I have a jsp called home.jsp that im trying to show a category tree on. Im trying to use the javascript from this site http://www.destroydrop.com/javascripts/tree/
but when i deploy the webapp the home.jsp cant load the dtree.js.
Heres my setup.....
Directory layout
web
index.jsp
images
js
dtree.js
WEB-INF
classes
jsp
home.jsp
My web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocations</param-name>
<param-value>
/WEB-INF/shop-data.xml,/WEB-INF/applicationContext.xml, /WEB-INF/shop-servlet.xml
</param-value>
</context-param>
<servlet>
<servlet-name>shop</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>shop</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
</web-app>
My shop-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/jdbc.properties</value>
</list>
</property>
</bean>
<!-- TransactionInterceptor -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.Transa ctionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>${jdbc.driverClassName}</value></property>
<property name="url"><value>${jdbc.url}</value></property>
<property name="username"><value>${jdbc.username}</value></property>
<property name="password"><value>${jdbc.password}</value></property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>
<!-- DAO -->
<bean id="dao" class="com.benshort.dao.jdbc.JdbcCatalogDao">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<!-- Business Objects -->
<bean id="catalogTarget" class="com.benshort.service.CatalogImp">
<property name="catalogDao">
<ref bean="dao"/>
</property>
</bean>
<bean name="/home.html" class="com.benshort.web.HomePageController" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default" >
<property name="catalog">
<ref bean="catalogTarget"/>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
</bean>
</beans>
My index.jsp
<jsp:forward page="home.html" />
My home.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<html>
<head>
<link rel="stylesheet" type="text/css" media="print" href="<c:url value='/style/dtree.css'/>"/>
<script type="text/javascript" src="<c:url value='/js/dtree.js'/>"></script>
</head>
<body>
<div class="dtree">
<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>
<script type="text/javascript">
d = new dTree('d');
d.add(0, -1, 'My example tree');
d.add(1, 0, 'Node 1', 'example01.html');
d.add(2, 0, 'Node 2', 'example01.html');
d.add(3, 1, 'Node 1.1', 'example01.html');
d.add(4, 0, 'Node 3', 'example01.html');
d.add(5, 3, 'Node 1.1.1', 'example01.html');
d.add(6, 5, 'Node 1.1.1.1', 'example01.html');
d.add(7, 0, 'Node 4', 'example01.html');
d.add(8, 1, 'Node 1.2', 'example01.html');
d.add(9, 0, 'My Pictures', 'example01.html', 'Pictures I\'ve taken over the years', '', '', 'img/imgfolder.gif');
d.add(10, 9, 'The trip to Iceland', 'example01.html', 'Pictures of Gullfoss and Geysir');
d.add(11, 9, 'Mom\'s birthday', 'example01.html');
d.add(12, 0, 'Recycle Bin', 'example01.html', '', '', 'img/trash.gif');
document.write(d);
</script>
</div></body>
</html>
Im tryng to learn spring and am implementing a e shop framework, i have all my service and data acess working but am having trouble with the web stuff.
I have a jsp called home.jsp that im trying to show a category tree on. Im trying to use the javascript from this site http://www.destroydrop.com/javascripts/tree/
but when i deploy the webapp the home.jsp cant load the dtree.js.
Heres my setup.....
Directory layout
web
index.jsp
images
js
dtree.js
WEB-INF
classes
jsp
home.jsp
My web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<context-param>
<param-name>contextConfigLocations</param-name>
<param-value>
/WEB-INF/shop-data.xml,/WEB-INF/applicationContext.xml, /WEB-INF/shop-servlet.xml
</param-value>
</context-param>
<servlet>
<servlet-name>shop</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>shop</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
<taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
<taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
<taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>
</web-app>
My shop-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyP laceholderConfigurer">
<property name="locations">
<list>
<value>/WEB-INF/jdbc.properties</value>
</list>
</property>
</bean>
<!-- TransactionInterceptor -->
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.Transa ctionInterceptor">
<property name="transactionManager">
<ref bean="transactionManager"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_SUPPORTS,readOnly</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName"><value>${jdbc.driverClassName}</value></property>
<property name="url"><value>${jdbc.url}</value></property>
<property name="username"><value>${jdbc.username}</value></property>
<property name="password"><value>${jdbc.password}</value></property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTran sactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>
<!-- DAO -->
<bean id="dao" class="com.benshort.dao.jdbc.JdbcCatalogDao">
<property name="dataSource">
<ref bean="dataSource"/>
</property>
</bean>
<!-- Business Objects -->
<bean id="catalogTarget" class="com.benshort.service.CatalogImp">
<property name="catalogDao">
<ref bean="dao"/>
</property>
</bean>
<bean name="/home.html" class="com.benshort.web.HomePageController" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default" >
<property name="catalog">
<ref bean="catalogTarget"/>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="prefix">
<value>/WEB-INF/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
</bean>
</beans>
My index.jsp
<jsp:forward page="home.html" />
My home.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<html>
<head>
<link rel="stylesheet" type="text/css" media="print" href="<c:url value='/style/dtree.css'/>"/>
<script type="text/javascript" src="<c:url value='/js/dtree.js'/>"></script>
</head>
<body>
<div class="dtree">
<p><a href="javascript: d.openAll();">open all</a> | <a href="javascript: d.closeAll();">close all</a></p>
<script type="text/javascript">
d = new dTree('d');
d.add(0, -1, 'My example tree');
d.add(1, 0, 'Node 1', 'example01.html');
d.add(2, 0, 'Node 2', 'example01.html');
d.add(3, 1, 'Node 1.1', 'example01.html');
d.add(4, 0, 'Node 3', 'example01.html');
d.add(5, 3, 'Node 1.1.1', 'example01.html');
d.add(6, 5, 'Node 1.1.1.1', 'example01.html');
d.add(7, 0, 'Node 4', 'example01.html');
d.add(8, 1, 'Node 1.2', 'example01.html');
d.add(9, 0, 'My Pictures', 'example01.html', 'Pictures I\'ve taken over the years', '', '', 'img/imgfolder.gif');
d.add(10, 9, 'The trip to Iceland', 'example01.html', 'Pictures of Gullfoss and Geysir');
d.add(11, 9, 'Mom\'s birthday', 'example01.html');
d.add(12, 0, 'Recycle Bin', 'example01.html', '', '', 'img/trash.gif');
document.write(d);
</script>
</div></body>
</html>