1

I am trying to run a springMVC application but its showing blank page to me.

In my controller class I have

@Controller
public class LoginController extends CommonController {

    @RequestMapping("/login")
        public ModelAndView login(HttpSession session, HttpServletResponse response, HttpServletRequest request, Model model) {
         logger.info("something"); // printing something in logs
         return new ModelAndView("login");//But failing here not loading login.jsp
    }
}

Its coming inside login method as if I print something before return its printing but failing at return statement and i am not getting any exception

Inside my spring-servlet.xml. I have

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:annotation-config />
    <context:component-scan base-package="com.jemmmedia.organise" />

    <!-- Enable annotation driven controllers, validation etc... -->
    <mvc:annotation-driven />

--------
-------

<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
       p:prefixJson="true" />

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

and my login.jsp is at /core/src/main/webapp/WEB-INF/jsp/login.jsp

and inside pom.xml I have

<properties>
        <spring.version>3.0.7.RELEASE</spring.version>
    </properties>
<dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>
        <!--spring -->

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.security</groupId>
                    <artifactId>spring-security-web</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.security</groupId>
                    <artifactId>spring-security-config</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.7.2</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.7.2</version>
        </dependency>

my web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>mvnproject</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <listener>
    <listener-class>
      org.springframework.security.web.session.HttpSessionEventPublisher
    </listener-class>
  </listener>

  <!-- Spring Security -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring-servlet.xml,
            /WEB-INF/spring-security.xml
        </param-value>
    </context-param>

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

      <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config> 

    <error-page>
        <error-code>404</error-code>
        <location>/error404</location>
    </error-page>

    <error-page>
        <error-code>403</error-code>
        <location>/error403</location>
    </error-page>

    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/exception</location>
    </error-page>

My logs are aready set to Debug level and it seems there is no error and some of last files from logs are

'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
[ INFO] 2014-04-16 21:53:53 Mapped URL path [/files/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#1'
[ INFO] 2014-04-16 21:53:53 Mapped URL path [/profileImages/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#2'
[ INFO] 2014-04-16 21:53:53 Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#0'
[ INFO] 2014-04-16 21:53:53 Mapped URL path [/**] onto handler 'org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler#1'
[ INFO] 2014-04-16 21:53:53 Starting beans in phase 2147483647
[ INFO] 2014-04-16 21:53:53 Starting Quartz Scheduler now
[ INFO] 2014-04-16 21:53:53 FrameworkServlet 'spring': initialization completed in 670 ms
3
  • If you have logging configured, turn it to debug level and post it here. Also lets see whats there in your web.xml
    – Prasad
    Apr 16, 2014 at 20:53
  • Hi Prasad, I have added my web.xml and my logs. please let me know if you need more information
    – Harry
    Apr 16, 2014 at 21:02
  • The JSP itself might be useful. Plus the directory structure under WEB-INF/jsp Apr 23, 2014 at 12:19

3 Answers 3

2
+50

I had some issues at work; now I was able in checking your code; here my steps:

  • I downloaed the github source code
  • I executed a mvn clean install on order to download all the needed libraries

Now all the libraries have been downloaded and I started in checked the issue. First of all in the main pom I had to add the following dependendcies:

<!--Angelo-->
<dependency>
    <groupId>org.simpleframework</groupId>
    <artifactId>simple-xml</artifactId>
    <version>2.7.1</version>
</dependency>
<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.9</version>
</dependency>
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>  
<!--Fine Angelo-->

By adding these dependencies, everything compiled just fine. But issues didn't finish here; infact in the iBatis mapper file you had a lot of wrong class names. I guess that you (or somebody else) did a refactoryng of the model classes and forgot to update the mapper files (and I'm wondering how this code could run on your tomcat)

So I modified all the XML files and I tried to launche the application; I had to modify also the spring-security.xml file by adding this intestation:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:util="http://www.springframework.org/schema/util"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/security 
        http://www.springframework.org/schema/security/spring-security.xsd
        http://www.springframework.org/schema/util 
        http://www.springframework.org/schema/util/spring-util.xsd">

Once I did this I run again the server and the application started with no error; when I typed the url for the login page, the com.jemmmedia.organise.service.impl.controller.LoginController.login(HttpSession, HttpServletResponse, HttpServletRequest, Model, FeedEntryBean, int, int, String)has been successfully called; and as it happened to you the ModelAndView for login was null This is the console output:

18:48:06,932 INFO  [LoginController] model View: ModelAndView: reference to view with name 'login'; model is null

But, eve if the modelandview is null, the login page appears to me

So basically I strongly suggest to yuo to check the mappers files and the spring-security file

I hope this can help Cheers, Angelo

1
  • Thanks a lot Angelo.. I am very happy and very relieved for this. I'll check this today evening. Up vote for this :). Thanks again
    – Harry
    Apr 24, 2014 at 7:09
0

I guess that it's returning results in JSON format; try to check with firebug the response; if the server response is in JSON format, this is related to the fact that you have 2 viewResolser; yuo should use a ContentNegotiationgViewResolver

11
  • Hi Angelo I have test it in both chrome and firefox it just displaying the blank page with head tag with style tag and body tag is empty and I tried with ContentNegotiationViewResolver and getting the exception "nested exception is java.lang.ClassNotFoundException: org.springframework.web.servlet.view.ContentNegotiationgViewResolver "
    – Harry
    Apr 16, 2014 at 19:12
  • I removed MappingJacksonJsonView but still I am getting the same blank page
    – Harry
    Apr 16, 2014 at 19:30
  • It does not make any difference even I comment both the view resolvers
    – Harry
    Apr 16, 2014 at 21:24
  • From your log file fragment I see that the login url is not mapped...is the controller in a package that you scan (e.g. in com.jemmmedia.organise o any sub-package? Apr 17, 2014 at 6:53
  • Hi Angelo, if it would not have scanning then it would not have print the logger info. Could it be any other reason also if there is sub-package ?
    – Harry
    Apr 17, 2014 at 10:23
0

Why you need this below config?

<bean class="org.springframework.web.servlet.view.json.MappingJacksonJsonView"
p:prefixJson="true" />

I think it will work well when you remove above bean.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.