Spring项目的Glassfish 404错误

时间:2012-11-23 17:54:23

标签: eclipse spring spring-mvc glassfish http-status-code-404

我有 Glassfish3 服务器,它与 Eclipse Helios集成

我已通过右键单击服务器使用“添加和删除”将我的示例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>

我的 dispatcher-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

2 个答案:

答案 0 :(得分: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>
目录。

谢谢你,编码愉快!

答案 1 :(得分: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>

更新您已在根Application Context instead of the Dispatcher Servlet Context中声明<mvc:annotation-driven />,这可能会导致一些问题,例如viewResolver将从根应用程序上下文中有效地隐藏

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