0

Here is the controller that I use

@Controller

public class ProjectController {

    @Autowired

    private ProjectService ProjectService;

    @Autowired
    public ProjectController(ProjectService ProjectService){
        this.ProjectService = ProjectService;
    }


        @RequestMapping({"/","/find"})
        public String getPersonList(@RequestParam("regNo") String regNo, ModelMap model) {  

            model.addAttribute("ProjectList", ProjectService.getStudentProject(regNo));  

            return "find";  
        }  
}

I have a page called find.jsp under WEB-INF/jsp folder. But when I hit localhost:8080/find I get

HTTP status 400 error

Following is my dispatcher-servlet.xml where I have made the mappings

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:beans="http://springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans/spring-beans.xsd 
       http://www.springframework.org/schema/context/spring-context.xsd       
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/task/spring-task.xsd">

    <mvc:annotation-driven/>

    <context:component-scan base-package="com.MyAppName.www" />

    <!-- Factory bean that creates the Mongo instance -->
    <bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
        <property name="host" value="localhost" />
    </bean>

    <!-- MongoTemplate for connecting and quering the documents in the database -->
    <bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
        <constructor-arg name="mongo" ref="mongo" />
        <constructor-arg name="databaseName" value="MyApp" />
    </bean>

    <!-- Use this post processor to translate any MongoExceptions thrown in @Repository annotated classes -->
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <bean id="jspViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp"
          p:suffix=".jsp" /> 

    <bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>

    <bean class=
    "org.springframework.web.servlet.view.tiles2.TilesConfigurer">
  <property name="definitions">
    <list>
      <value>/WEB-INF/views/views.xml</value>
    </list>
  </property>
</bean>    

</beans>

This is how web.xml looks

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5">

  <display-name>Spring With MongoDB Web Application</display-name>

    <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>/</url-pattern>
    </servlet-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <welcome-file-list>
       <welcome-file>/WEB-INF/find.jsp</welcome-file>
    </welcome-file-list> 
</web-app>

This is how my server log looks like. I am using Tomcat 7.0

Sep 12, 2014 1:24:21 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Sep 12, 2014 1:24:21 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 12, 2014 1:24:21 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 502 ms

The url I use is localhost:8080/find.jsp and I get 404 error.

I also have a problem in definition tag of views.xml

<!DOCTYPE tiles-definitions PUBLIC
      "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
      "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">

<tiles-definitions>
   <definition name="template" template="/WEB-INF/jsp/main_template.jsp">
     <put-attribute name="top"
                    value="/WEB-INF/jsp/tiles/header.jsp" />
     <put-attribute name="side"
                    value="/WEB-INF/jsp/tiles/footer.jsp" />

   </definition>

    <definition name="home" extends="template">Define home tile
             <put-attribute name="content" value="/WEB-INF/jsp/find.jsp" />
    </definition>
</tiles-definitions>
sofs1
  • 3,834
  • 11
  • 51
  • 89

1 Answers1

0

Change ProjectService attribute to start lowercase. Remove the @RequestParam since this is a start page.

 @Controller
    public class ProjectController {

    @Autowired
    private ProjectService projectService;

     @RequestMapping(value={"/","/find"} , method = RequestMethod.GET)
     public String getPersonList(ModelMap model) {  

                model.addAttribute("ProjectList", projectService.getStudentProject());  

                return "find";  
     }  
 }
Rafik BELDI
  • 4,140
  • 4
  • 24
  • 38