1

I have Glassfish3 server which is integrated with Eclipse Helios

I have added my sample Spring project to server using Add and Remove by right clicking server.

When I run http://localhost:8080/SpringHibernateJSFTest/insertJdbcContact.do

I am getting description The requested resource () is not available.

How can I resolve this error? What am I doing wrong?

Any help is highly appreciated.

My 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;
    }
}

Here is 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>

My 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>

My 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>

I have JdbcInsert.jsp in /WebContent/WEB-INF

Update 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
Jacob
  • 14,463
  • 65
  • 207
  • 320

2 Answers2

1

You should move:

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

to 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/ directory.

Thanks and happy coding!

Sazzadur Rahaman
  • 6,938
  • 1
  • 30
  • 52
  • You mean id `viewResolver`? I tried with the id as well as with jsp, but didn't resolve the error. Correct If I am missing something silly here. – Jacob Nov 23 '12 at 19:14
  • @Polppan are you still having the problem? – Sazzadur Rahaman Nov 23 '12 at 19:43
  • Yes I have created jsp folder under WEB-INF and moved the file. Now I am getting the other errors( I have included in my question) when I build project, though I have `applicationContext.xml`. – Jacob Nov 23 '12 at 19:49
  • I have managed to resolve the above error, however I am still getting 404 status. – Jacob Nov 23 '12 at 19:57
  • When I build project all files gets deployed to glassfish automatically. When I checked glassfish folders I have noticed that jsp folder has not copied to glassfish, so I copied the folder to glassfish manually. However when I build project again jsp folder goes missing in glassfish. So I am suspecting something to do with this. – Jacob Nov 23 '12 at 20:07
  • Then the problem is in your build script. and also you should address to the problems I pointed in my last modification. – Sazzadur Rahaman Nov 23 '12 at 20:12
  • I have resolved the problem pointed in your last modification by moving jsp files to jsp folder inside WEB-INF. – Jacob Nov 23 '12 at 20:17
  • what about resolving the comma? I mentioned in your ``. that should be `` and should reside in dispathcer-servlet.xml along with ``. – Sazzadur Rahaman Nov 23 '12 at 20:20
  • I have two packages `com.controller and com.beans` and that's why it is separated by comma. _and should reside in dispathcer-servlet.xml along with _ Could you be more specific here as I did not understand. – Jacob Nov 23 '12 at 20:24
  • The two line should be in `dispathcer-servlet.xml` – Sazzadur Rahaman Nov 23 '12 at 20:28
  • ` ` I have moved from applicationContext.xml to dispatcher-servlet.xml. But still I am getting 404 status. – Jacob Nov 23 '12 at 20:57
1

Your ViewResolver uses /WEB-INF/jsp/ prefix, while JdbcInsert.jsp is located in /WEB-INF, you should correct the prefix to "/WEB-INF/"

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

update You have declared <mvc:annotation-driven /> in the root Application Context instead of the Dispatcher Servlet Context, this may cause some problems, for example viewResolver will be effectively invisible from the root application context.

Your mvc configuration should reside in the dispatcher servlet context.

Community
  • 1
  • 1
Boris Treukhov
  • 17,493
  • 9
  • 70
  • 91
  • I have changed from `/WEB-INF/jsp/` to v/WEB-INF/`, but when I tried `http://localhost:8080/SpringHibernateJSFTest/insertJdbcContact.do`, I am getting same errors – Jacob Nov 23 '12 at 19:24