1

我有与Eclipse Helios集成的Glassfish3服务器

我已经通过右键单击服务器使用添加和删除将我的示例 Spring 项目添加到服务器。

当我跑http://localhost:8080/SpringHibernateJSFTest/insertJdbcContact.do

我正进入(状态description The requested resource () is not available.

如何解决此错误?我究竟做错了什么?

非常感谢任何帮助。

我的controller class

 @Controller
public class JBTJdbcController {
    @Autowired
    com.service.SpringJdbcService mfssService;
    @RequestMapping(value = "/insertJdbcContact", method = RequestMethod.GET)
    public ModelAndView insertMemDtls() {
        ModelAndView mav = new ModelAndView("JdbcInsert");
        VngMem mfssbean = new VngMem();
        mav.addObject("insertUser", mfssbean);
        mav.addObject("status", "success");
        return mav;
    }
    @RequestMapping(value = "/insertJdbcContact", method = RequestMethod.POST)
    public ModelAndView insertContact(
            @ModelAttribute("insertUser") VngMem vngmem) {
        ModelAndView mav = new ModelAndView("JdbcInsert");
        try {
            mfssService.insertMfssMemDts(vngmem);
        } catch (Exception e) {
            e.printStackTrace();
        }
        mav.addObject("searchResultPost", vngmem);
        return mav;
    }
}

这是web.xml

<display-name>SpringHibernateJSFTest</display-name>
    <display-name>SpringMVC</display-name>
    <welcome-file-list>
        <welcome-file>welcome.do</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:applicationContext.xml</param-value>
    </context-param>
</web-app>

我的applicationContext.xml

<context:annotation-config />
<context:component-scan base-package="com.controller,com.beans" />
<mvc:annotation-driven />
  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="url" value="jdbc:oracle:thin:@server:1521:orcl"/>
        <property name="username" value="scott"/>
        <property name="password" value="tiger"/>

    </bean>
<bean id="SpringJdbcDao"  class="com.dao.SpringJdbcDaoImpl">
  <property name="dataSource" ref="dataSource"/>
</bean>
  <bean id="SpringJdbcService"  class="com.service.SpringJdbcServiceImpl">
  <property name="springJdbcDao" ref="SpringJdbcDao"/>
</bean>
</beans>

我的调度程序-servlet.xml

 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp"/>
    </bean>
</beans>

JdbcInsert.jsp/WebContent/WEB-INF

更新 1

cannot Deploy SpringHibernateJSFTest
Deployment Error for module: SpringHibernateJSFTest: Exception while loading the app :
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: 
org.apache.catalina.LifecycleException: 
org.springframework.beans.factory.BeanDefinitionStoreException: 
IOException parsing XML document from class path resource [applicationContext.xml];
 nested exception is java.io.FileNotFoundException: class path resource 
 [applicationContext.xml] cannot be opened because it does not exist
4

2 回答 2

1

你应该搬家:

    <context:component-scan base-package="com.controller,com.beans" />
    <mvc:annotation-driven />

dispatcher-servlet.xml.

In your dispacher-servlet.xml the id of your InternalResourceViewResolver bean should be internalResourceViewResolver, like bellow:

  <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jsp/"/>
    <property name="suffix" value=".jsp"/>
</bean>

And your jsp files should be in /WEB-INF/jsp/目录。

感谢和快乐的编码!

于 2012-11-23T18:57:46.263 回答
1

ViewResolver使用/WEB-INF/jsp/前缀,而JdbcInsert.jsp位于 中时/WEB-INF,您应该将前缀更正为"/WEB-INF/"

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
                <property name="prefix" value="/WEB-INF/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

更新您已<mvc:annotation-driven />在根应用程序上下文中声明,而不是在 Dispatcher Servlet 上下文中声明,这可能会导致一些问题,例如viewResolver从根应用程序上下文中实际上是不可见的。

您的 mvc 配置应该驻留在调度程序 servlet 上下文中。

于 2012-11-23T19:15:24.957 回答