spring MVC with maven

Hi,

 i was going through below example

http://www.srccodes.com/p/article/24/spring-3-mvc-framework-based-hello-world-web-application-example-using-maven-eclipse-ide-and-tomcat-server

I did everything as suggested.


when i right click on project and run as server getting
http://localhost:8080/SpringMVCHelloWorld/
with output on page as
Hello World!

my question is above output is coming from index.jsp or from helloWorld.jsp. How do i know, how do i debug web application with only jsp's in it to see the above message from which jsp page.

what is the meaning

<html>
<body>
<h2>${message}</h2>
</body>
</html>

where the message is being and get in this application




Please advise. Any ideas, resources, sample code highly appreciated. thanks in advance
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Ok, here is a high level of what is happening so you can understand it all...

- Firstly, Tomcat gets the request for "/SpringMVCHelloWorld/" and it knows that you web app is deployed with that name so it sends the request of to your webapp, from now on you can forget the "/SpringMVCHelloWorld" part of the URL, it has already been handled.
- So your webapp (effectively) sees a request for URL path "/" and due to this line in web.xml "<url-pattern>/</url-pattern>" it knows to send this request to the servlet with that mapping, which is the Spring DispatcherServlet also defined in web.xml.
- The DispatcherServlet knows about the Controller class that you have implemented due to the "@Controller" annotation on that class and also due to the "<context:component-scan base-package="com.srccodes.spring.controller" />" line in your dispatcher-servlet.xml file.
- This controller has indicated using the line "@RequestMapping("/")" that the "printHelloWorld" method will handle requests for the URL path of "/" and so THAT is the method that gets called.
- In that method "model.addAttribute("message", "Hello World!");" we set an attribute in the MODEL called "message" and it has "Hello World!" as its value, this is one part of the answer to your questions above.
- At the end of the method it returns "helloWorld", this is what is called the VIEW. When control returns to DispatcherServlet (who called this printHelloWorld method of your controller) it takes this abstract view name and attempts to translate it into something real. Due to the configuration of the "viewResolver" in your dispatcher-servlet.xml file it adds "/WEB-INF/pages" to the front of the view name and ".jsp" the the end of the view name to get this... "/WEB-INF/pages/helloWorld.jsp". This answers another part of your question, which JSP page is being used.
- Finally, the DispatcherServlet does an internal "forward" to that JSP page but also passes the model object to it, which in this case was the Map with the one entry mapping message -> "Hello World!" and so the JSP can use this model, via a line like "<h2>${message}</h2>" where it accesses "message" and "Hello World!" gets returned in its place. This hopefully answers the final part of your question.



If you need clarification on any of the above, let me know.
0
gudii9Author Commented:
Finally, the DispatcherServlet does an internal "forward" to that JSP page but also passes the model object to it, which in this case was the Map with the one entry mapping message -> "Hello World!" and so the JSP can use this model, via a line like "<h2>${message}</h2>" where it accesses "message" and "Hello World!" gets returned in its place.




where 'message' defined in model. i do not remember defining neither model not message inside model. please advise
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
where 'message' defined in model
As I said in the 5th point of my post above, this is achieved by this line of code...
model.addAttribute("message", "Hello World!");

Open in new window

Which in line 17 of the SpringMVCHellowWorldController.java as posted in that link that you have provided. And to expand a little, Spring provides you with the "model" to set any values against, see the line preceding it in the code, where "Model model" is an argument of the printHellowWorld() method. Spring is calling this method in order to handle the request and it is providing the "model" to you.

Is that clearer?
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

gudii9Author Commented:
when i changed

Hello World! ------->Hello World!!!!
in the index.jsp it printed -->Hello World!!!!( did not print--> Hello World!) which makes me wonder it is coming from index.jsp itself not through spring framework flow?

How to debug jsp in eclipse. I know how to debug jav files by putting break point then clicking F6 etc but never had luck debugging jsp in eclipse in similar way.

Please advise
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
when i changed

Hello World! ------->Hello World!!!!
in the index.jsp

I can't see how you could change from "Hello World!" to "Hello World!!!" in your index.jsp when this ISN'T any "Hello World!" in index.jsp to start with.

If I am not understanding you properly, then please post all files that you have updated (ie. ones that are different from the example in the link you provided) so that I can see what you have done.


As for debugging JSP files, I really haven't ever done anything too complicated in JSP's that have required debugging, so I can't really help here. The limited amount that I have done is along similar lines to debugging Java code by putting "System.out.println" statements in to display particular values and certain points of the code. You can use JSP to output values of variables/objects to the actual HTML page in a similar way.

And anyway, the generally accepted best practise these days, is to use JSP's just to display content that you have added to your model. Any "logic" should be moved/placed into your controller code, leaving the JSP for simple displaying/formatting, etc.
0
gudii9Author Commented:
Let me double check and get baack to you
0
gudii9Author Commented:
I see index.jsp in  the code which is printing

Hello World!!!!



I am attaching the code and screenshot for your reference. Please advise how to avoid output coming from index.jsp but to get output from spring framework flow. please advise

web.xml looks like

<?xml version="1.0" encoding="UTF-8"?>
<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">
 
    <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>
</web-app>


dispatcher-servlet.xml looks like

<?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.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
 
    <context:component-scan base-package="com.srccodes.spring.controller" />
    <mvc:annotation-driven />
     
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>




index.jsp looks like

<html>
<body>
<h2>Hello World!!!!</h2>
</body>
</html>



SpringMVCHelloController looks like



package com.srccodes.spring.controller;
 
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
/**
 * @author Abhijit Ghosh
 * @version 1.0
 */
 
@Controller
public class SpringMVCHelloController {
 
    @RequestMapping("/")
    public String printHelloWorld(Model model) {
        model.addAttribute("message", "Hello World!");
 
        return "helloWorld";
    }
}




SpringSecurityHelloController looks like

package com.srccodes.spring.controller;
 
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
/**
 * @author Abhijit Ghosh
 * @version 1.0
 */
 
@Controller
public class SpringSecurityHelloController {
 
    @RequestMapping("/public")
    public String accessPublicPage(Model model) {
        model.addAttribute("message", "This page is publicly accessible. No authentication is required to view.");
 
        return "public";
    }
     
    @RequestMapping("/secured/mypage")
    public String accessSecuredPage(Model model) {
        model.addAttribute("message", "Only you are authenticated and authorized to view this page.");
 
        return "/secured/mypage";
    }
}



pom.xml looks like

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.srccodes.spring</groupId>
  <artifactId>SpringMVCHelloWorld</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>SpringMVCHelloWorld Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
        <org.springframework.version>3.1.2.RELEASE</org.springframework.version>
    </properties>
 
    <dependencies>
        <!-- Spring MVC depends on spring-core, spring-beans, spring-context, spring-web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    </dependencies>
 
    <build>
        <finalName>SpringMVCHelloWorld</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Open in new window

SpringMaven1.1.jpg
0
gudii9Author Commented:
When i deleted index.jsp as it is not mentioned in the example but the eclipse seems put that by default i am getting below error. please advise


HTTP Status 404 -

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

type Status report

message

description The requested resource is not available.


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

Apache Tomcat/6.0.37
SpringMaven1.2.jpg
0
gudii9Author Commented:
I see a warning on my web.xml which says as below. please advise

servlet-class references to "org.springframework.web.servlet.DispatcherServlet" that does not
 implement interface javax.servlet.Servlet
SpringMaven1.4.jpg
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Sorry, I should have re-checked the link. When you said "index.jsp" I was still thinking of "helloWorld.jsp". But look again at the link that YOU posted... there is NO file called index.jsp, if one has been created for you when you create a new project, delete it. Make sure you ONLY have the same files as those listed in the tutorial in your link.
0
gudii9Author Commented:
when i remove index.jsp getting


HTTP Status 404 -

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

type Status report

message

description The requested resource is not available.




i wonder why application is looking for index.jsp.

i do not havwe anby reference to index.jsp from web.xml also.

i see one warning in web.xml for dispatcher servet entry as below

servlet-class references to "org.springframework.web.servlet.DispatcherServlet" that does not implement interface
 javax.servlet.Servlet

How to fix that error. please advise
0
gudii9Author Commented:
My console looks like below

Oct 20, 2013 2:57:13 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre7/bin/client;C:/Program Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Java\jdk1.6.0_41\bin;C:\software\eclipse-jee-juno-SR1-win32\eclipse;;.
Oct 20, 2013 2:57:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringSecurityHelloWorld' did not find a matching property.
Oct 20, 2013 2:57:13 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpringMVCHelloWorld' did not find a matching property.
Oct 20, 2013 2:57:13 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Oct 20, 2013 2:57:13 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 852 ms
Oct 20, 2013 2:57:13 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Oct 20, 2013 2:57:13 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.37
Oct 20, 2013 2:57:14 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Oct 20, 2013 2:57:14 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
Oct 20, 2013 2:57:14 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sun Oct 20 14:57:14 EDT 2013]; root of context hierarchy
Oct 20, 2013 2:57:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Oct 20, 2013 2:57:15 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1fb7b50: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,viewResolver,org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0]; root of factory hierarchy
Oct 20, 2013 2:57:16 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 1411 ms
Oct 20, 2013 2:57:16 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Oct 20, 2013 2:57:16 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Oct 20, 2013 2:57:16 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Sun Oct 20 14:57:16 EDT 2013]; root of context hierarchy
Oct 20, 2013 2:57:16 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Oct 20, 2013 2:57:19 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-security.xml]
Oct 20, 2013 2:57:20 PM org.springframework.security.core.SpringSecurityCoreVersion <clinit>
INFO: You are running with Spring Security Core 3.1.4.RELEASE
Oct 20, 2013 2:57:20 PM org.springframework.security.config.SecurityNamespaceHandler <init>
INFO: Spring Security 'config' module version is 3.1.4.RELEASE
Oct 20, 2013 2:57:20 PM org.springframework.security.config.http.AuthenticationConfigBuilder createLoginPageFilterIfNeeded
INFO: No login page configured. The default internal one will be used. Use the 'login-page' attribute to set the URL of the login page.
Oct 20, 2013 2:57:20 PM org.springframework.security.config.http.HttpSecurityBeanDefinitionParser checkFilterChainOrder
INFO: Checking sorted filter chain: [Root bean: class [org.springframework.security.web.context.SecurityContextPersistenceFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 200, Root bean: class [org.springframework.security.web.authentication.logout.LogoutFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 400, <org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0>, order = 800, Root bean: class [org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1000, Root bean: class [org.springframework.security.web.authentication.www.BasicAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1200, Root bean: class [org.springframework.security.web.savedrequest.RequestCacheAwareFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1300, Root bean: class [org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1400, Root bean: class [org.springframework.security.web.authentication.AnonymousAuthenticationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1700, Root bean: class [org.springframework.security.web.session.SessionManagementFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1800, Root bean: class [org.springframework.security.web.access.ExceptionTranslationFilter]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null, order = 1900, <org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0>, order = 2000]
Oct 20, 2013 2:57:21 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1480605: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,viewResolver,org.springframework.security.filterChains,org.springframework.security.filterChainProxy,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.PortResolverImpl#0,org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint#0,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0,org.springframework.security.userDetailsServiceFactory,org.springframework.security.web.DefaultSecurityFilterChain#0,org.springframework.security.provisioning.InMemoryUserDetailsManager#0,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; root of factory hierarchy
Oct 20, 2013 2:57:22 PM org.springframework.security.web.DefaultSecurityFilterChain <init>
INFO: Creating filter chain: org.springframework.security.web.util.AnyRequestMatcher@1, [org.springframework.security.web.context.SecurityContextPersistenceFilter@1d22817, org.springframework.security.web.authentication.logout.LogoutFilter@461581, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@12de91e, org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter@123cde5, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@1a2b178, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@313e1e, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@e554e8, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@296ca1, org.springframework.security.web.session.SessionManagementFilter@19ac651, org.springframework.security.web.access.ExceptionTranslationFilter@51f7d7, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@16682fe]
Oct 20, 2013 2:57:22 PM org.springframework.security.config.http.DefaultFilterChainValidator checkLoginPageIsntProtected
INFO: Checking whether login URL '/spring_security_login' is accessible with your configuration
Oct 20, 2013 2:57:22 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 5967 ms
Oct 20, 2013 2:57:22 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'dispatcher'
Oct 20, 2013 2:57:22 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization started
Oct 20, 2013 2:57:22 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Sun Oct 20 14:57:22 EDT 2013]; parent: Root WebApplicationContext
Oct 20, 2013 2:57:22 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/dispatcher-servlet.xml]
Oct 20, 2013 2:57:23 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1912745: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver#0,org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver#0,org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver#0,org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter,viewResolver,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@1480605
Oct 20, 2013 2:57:24 PM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'dispatcher': initialization completed in 1665 ms
Oct 20, 2013 2:57:24 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Oct 20, 2013 2:57:24 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Oct 20, 2013 2:57:24 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/79  config=null
Oct 20, 2013 2:57:24 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 10340 ms
Oct 20, 2013 2:57:24 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/SpringMVCHelloWorld/] in DispatcherServlet with name 'dispatcher'


Is this example running on your local machine. please advise
0
gudii9Author Commented:
I do not have maven installed on my vista machine.
As in this link
http://www.avajava.com/tutorials/lessons/how-do-i-set-the-location-of-my-local-maven-repository.html

I installed and checked from command prompt as

mvn -version it shows mvn3

then i followed this link
https://www.youtube.com/watch?v=YeC7XQho-O0

I got successful output as attached.


Now i extened the above working example to incorporate spring mvc

then i am getting error as below
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[WARNING] The POM for org.apache.tomcat.maven:tomcat6-compiler-plugin:jar:6 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat6-compiler-plugin:6: Plugin org.apache.tomcat.maven:tomcat6-compiler-plugin:6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.tomcat.maven:tomcat6-compiler-plugin:jar:6
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building myFirstWebApplication 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.apache.tomcat.maven:tomcat6-compiler-plugin:jar:6 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat6-compiler-plugin:6: Plugin org.apache.tomcat.maven:tomcat6-compiler-plugin:6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.tomcat.maven:tomcat6-compiler-plugin:jar:6
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) @ myFirstWebApplication >>>
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myFirstWebApplication ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\ganesha\eclipseJuno_workspace\ljn_servletsJspJsf_adv\myFirstWebApplication\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ myFirstWebApplication ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\ganesha\eclipseJuno_workspace\ljn_servletsJspJsf_adv\myFirstWebApplication\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.440s
[INFO] Finished at: Sun Oct 20 23:34:53 EDT 2013
[INFO] Final Memory: 7M/19M
[INFO] ------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project myFirstWebApplication: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre7\..\lib\tools.jar -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

My code is


controller looks like

package com.srccodes.spring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
 
/**
 * @author Abhijit Ghosh
 * @version 1.0
 */
 
@Controller
public class SpringMVCHelloController {
 
    @RequestMapping("/")
    public String printHelloWorld(Model model) {
        model.addAttribute("message", "Hello World!");
 
        return "helloWorld";
    }
}


index.jsp looks like

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</html>


pom.xml looks like

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.ag.web</groupId>
  <artifactId>myFirstWebApplication</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>myFirstWebApplication</name>
  <url>http://maven.apache.org</url>

 <properties>
        <org.springframework.version>3.1.2.RELEASE</org.springframework.version>
    </properties>
 
   
      
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
      <!-- Spring MVC depends on spring-core, spring-beans, spring-context, spring-web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
  
  </dependencies>
  
  

  <build>
    <plugins>
     <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat6-compiler-plugin</artifactId>
        <version>6</version>      
      </plugin>
    </plugins>
  </build>
</project>



dispatcher-servlet.xml looks like


<?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.1.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.1.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
 
    <context:component-scan base-package="com.srccodes.spring.controller" />
    <mvc:annotation-driven />
     
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>
</beans>


helloWorld.jsp looks like

<html>
<body>
<h2>${message}</h2>
</body>
</html>


web.xml looks like

<?xml version="1.0" encoding="UTF-8"?>
<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">
 
    <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>
</web-app>

Open in new window



project structure looks as in the attachment.

Please advise how to fix these errors
mavenOutput1.jpg
mavenOutput2.jpg
0
gudii9Author Commented:
when i changed the pom.xml as below
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.ag.web</groupId>
  <artifactId>myFirstWebApplication</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>myFirstWebApplication</name>
  <url>http://maven.apache.org</url>

 <properties>
        <org.springframework.version>3.1.2.RELEASE</org.springframework.version>
    </properties>
 
   
      
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
      <!-- Spring MVC depends on spring-core, spring-beans, spring-context, spring-web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
  
  </dependencies>
  
  

  <build>
    <plugins>   
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat6-compiler-plugin</artifactId>
        <version>6</version>      
            <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Open in new window



I am getting error as below
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[WARNING] The POM for org.apache.tomcat.maven:tomcat6-compiler-plugin:jar:6 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat6-compiler-plugin:6: Plugin org.apache.tomcat.maven:tomcat6-compiler-plugin:6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.tomcat.maven:tomcat6-compiler-plugin:jar:6
[INFO]                                                                        
[INFO] ------------------------------------------------------------------------
[INFO] Building myFirstWebApplication 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.apache.tomcat.maven:tomcat6-compiler-plugin:jar:6 is missing, no dependency information available
[WARNING] Failed to retrieve plugin descriptor for org.apache.tomcat.maven:tomcat6-compiler-plugin:6: Plugin org.apache.tomcat.maven:tomcat6-compiler-plugin:6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.tomcat.maven:tomcat6-compiler-plugin:jar:6
[INFO]
[INFO] >>> tomcat-maven-plugin:1.1:run (default-cli) @ myFirstWebApplication >>>
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ myFirstWebApplication ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\ganesha\eclipseJuno_workspace\ljn_servletsJspJsf_adv\myFirstWebApplication\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ myFirstWebApplication ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Users\ganesha\eclipseJuno_workspace\ljn_servletsJspJsf_adv\myFirstWebApplication\target\classes
[INFO] -------------------------------------------------------------
COMPILATION ERROR :
[INFO] -------------------------------------------------------------
Unable to locate the Javac Compiler in:
  C:\Program Files\Java\jre7\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.479s
[INFO] Finished at: Sun Oct 20 23:49:36 EDT 2013
[INFO] Final Memory: 7M/17M
[INFO] ------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project myFirstWebApplication: Compilation failure
Unable to locate the Javac Compiler in:
C:\Program Files\Java\jre7\..\lib\tools.jar
Please ensure you are using JDK 1.4 or above and
not a JRE (the com.sun.tools.javac.Main class is required).
In most cases you can change the location of your Java
installation by setting the JAVA_HOME environment variable.
-> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
0
gudii9Author Commented:
I tried to chnage pom.xml as below which did not work
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.ag.web</groupId>
  <artifactId>myFirstWebApplication</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>myFirstWebApplication</name>
  <url>http://maven.apache.org</url>

 <properties>
        <org.springframework.version>3.1.2.RELEASE</org.springframework.version>
    </properties>
 
   
      
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.4</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
      <!-- Spring MVC depends on spring-core, spring-beans, spring-context, spring-web -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
  
  </dependencies>
  
  

  <build>
    <plugins>   
      <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.5.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
    </plugins>
  </build>
</project>

Open in new window


I also tried to change version to 3.1.1 instead of 2.5.1 that also giving compilateion error.

Please advise
mavenOutput3.jpg
mavenOutput4.jpg
0
gudii9Author Commented:
If i use same pom as in link getting below error
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project myFirstWebApplication: Fatal error compiling: tools.jar not found: C:\Program Files\Java\jre7\..\lib\tools.jar -> [Help 1]
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Are those Maven error message that you are posting from Eclipse?

What are your Maven settings in Eclipse? In particular, Windows -> Preferences -> Maven -> Installations?
0
gudii9Author Commented:
correct.


Type 'webapp' in the 'Filter' field and select archetype 'maven-archetype-webapp' to generate a simple java web application using Maven. Click 'Next' button.


I see the youtube link i posted they have used

"mavan-j2EE1.4" as the archetype instead of 'maven-archetype-webapp'

Is there is any difference beween

mavan-j2EE1.4
vs
mavan-j2EE1.5
vs
mavan-j2EE1.6
vs
'maven-archetype-webapp'


Is there is any difference beween catalog selection at the top in the same page between

Internal
vs
AllCatalogs
vs
default local
vs
nexus indexer etc


please advise
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
correct.
So that, I think, is the reason that you are getting different results on command-line versus in Eclipse. The version of "mvn" that you are running on the command-line has the correct path to a Java JDK whereas the version that Eclipse is using has it's Java set to ONLY a JRE. And that is the reason why you are getting issues.

Is there is any difference beween

mavan-j2EE1.4
vs
mavan-j2EE1.5
vs
mavan-j2EE1.6
vs
'maven-archetype-webapp'
More than likely... I can't find any information on those J2EE archetypes but that is probably a big reason as to why you are seeing different things to what is in the link that you posted (which uses the webapp archetype)

Is there is any difference beween catalog selection at the top in the same page between
I would just leave that set to "All Catalogs", that way you see any archetype that you could possible use to start a new project. "All Catalogs" is just a combination of everything in the other three.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
>>The version of "mvn" that you are running on the command-line has the correct path to a Java JDK whereas the version that Eclipse is using has it's Java set to ONLY a JRE. And that is the reason why you are getting issues.




how do i check and change the maven version that is being pointed from eclipse. please advise
0
gudii9Author Commented:
please advise
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.