使用JB如何开发spring程序???
我用JB来做一个很简单的spring程序,
程序如下:
SpringappController.java
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 java.io.IOException;
public class SpringappController implements Controller {
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
return new ModelAndView("view.jsp", "model", "Hello, world!");
}
}
springapp-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="springappController" class="SpringappController"/>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/hello.c">springappController</prop>
</props>
</property>
</bean>
</beans>
view.jsp:
<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<html><head><title>View.jsp</title></head>
<body bgcolor="#FFFFFF">
Result: <c:out value="${model}" />
</body></html>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<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>*.c</url-pattern>
</servlet-mapping>
</web-app>
出现错误:
ContextConfig[/web]: Added certificates -> request attribute Valve
2004-9-17 14:15:02 org.springframework.web.servlet.HttpServletBean init
信息: Initializing servlet 'springapp'
2004-9-17 14:15:02 org.springframework.web.servlet.FrameworkServlet initServletBean
信息: Framework servlet 'springapp' init
2004-9-17 14:15:02 org.springframework.web.servlet.FrameworkServlet createWebApplicationContext
信息: Servlet with name 'springapp' will try to create custom WebApplicationContext context of class 'org.springframework.web.context.support.XmlWebApplicationContext' using parent context [null]
2004-9-17 14:15:03 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from resource [/WEB-INF/springapp-servlet.xml] of ServletContext
2004-9-17 14:15:03 org.springframework.context.support.AbstractXmlApplicationContext refreshBeanFactory
信息: Bean factory for application context [XmlWebApplicationContext for namespace 'springapp-servlet']: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [springappController,urlMapping]; Root of BeanFactory hierarchy
2004-9-17 14:15:03 org.springframework.context.support.AbstractApplicationContext refresh
信息: 2 beans defined in ApplicationContext [XmlWebApplicationContext for namespace 'springapp-servlet']
2004-9-17 14:15:03 org.springframework.context.support.AbstractApplicationContext initMessageSource
信息: No MessageSource found for context [XmlWebApplicationContext for namespace 'springapp-servlet']: using empty default
2004-9-17 14:15:03 org.springframework.context.support.AbstractApplicationContext initApplicationEventMulticaster
信息: No ApplicationEventMulticaster found for context [XmlWebApplicationContext for namespace 'springapp-servlet']: using default
2004-9-17 14:15:03 org.springframework.ui.context.support.UiApplicationContextUtils initThemeSource
信息: No ThemeSource found for [XmlWebApplicationContext for namespace 'springapp-servlet']: using ResourceBundleThemeSource
2004-9-17 14:15:03 org.springframework.context.support.AbstractApplicationContext refreshListeners
信息: Refreshing listeners
2004-9-17 14:15:03 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
信息: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [springappController,urlMapping]; Root of BeanFactory hierarchy]
2004-9-17 14:15:03 org.springframework.beans.factory.support.AbstractBeanFactory getBean
信息: Creating shared instance of singleton bean 'springappController'
2004-9-17 14:15:03 org.springframework.beans.factory.support.AbstractBeanFactory getBean
信息: Creating shared instance of singleton bean 'urlMapping'
2004-9-17 14:15:03 org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler
信息: Mapped URL path [/hello.c] onto handler [SpringappController@3bc473]
2004-9-17 14:15:03 org.springframework.web.servlet.FrameworkServlet initWebApplicationContext
信息: Using context class 'org.springframework.web.context.support.XmlWebApplicationContext' for servlet 'springapp'
2004-9-17 14:15:03 org.springframework.web.servlet.FrameworkServlet initWebApplicationContext
信息: Published WebApplicationContext of servlet 'springapp' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.springapp]
2004-9-17 14:15:03 org.springframework.web.servlet.DispatcherServlet initMultipartResolver
信息: Unable to locate MultipartResolver with name [multipartResolver]: no multipart handling provided
2004-9-17 14:15:03 org.springframework.web.servlet.DispatcherServlet initLocaleResolver
信息: Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@3dc0bb]
2004-9-17 14:15:03 org.springframework.web.servlet.DispatcherServlet initThemeResolver
信息: Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@1c5fde0]
2004-9-17 14:15:03 org.springframework.web.servlet.DispatcherServlet initHandlerAdapters
信息: No HandlerAdapters found in servlet 'springapp': using default
2004-9-17 14:15:03 org.springframework.web.servlet.DispatcherServlet initViewResolvers
信息: No ViewResolvers found in servlet 'springapp': using default
2004-9-17 14:15:03 org.springframework.web.servlet.FrameworkServlet initServletBean
信息: Framework servlet 'springapp' init completed in 500 ms
2004-9-17 14:15:03 org.springframework.web.servlet.HttpServletBean init
信息: Servlet 'springapp' configured successfully
StandardWrapper[/web:default]: Loading container servlet default