java - Spring MVC model attribute not displaying -
Output does not display "spring" to $ {message}
Does anyone show the value of my message Dependence?
I am already using Spring MVC but I have used XML configuration, am I being missed? Hope you can help me understand this.
& lt; Dependency & gt; & Lt; Dependency & gt; & Lt; Group & gt; JUnit & lt; / Group & gt; & Lt; ArtifactId & gt; JUnit & lt; / ArtifactId> & Lt; Version & gt; 3.8.1 & lt; / Edition & gt; & Lt; Scope & gt; Trial & lt; / Scope & gt; & Lt; / Dependencies & gt; & Lt; Dependency & gt; & Lt; Group & gt; Javax.servlet & lt; / Group & gt; & Lt; ArtifactId & gt; Javax.servlet-api & lt; / ArtifactId> & Lt; Version & gt; 3.1.0 & lt; / Edition & gt; & Lt; Scope & gt; Provided & lt; / Scope & gt; & Lt; / Dependencies & gt; & Lt ;! - Spring dependence - & gt; & Lt; Dependency & gt; & Lt; Group & gt; Org.springframework & lt; / Group & gt; & Lt; ArtifactId & gt; Spring-webmvc & lt; / ArtifactId> & Lt; Version & gt; $ {Spring.version} & lt; / Edition & gt; & Lt; / Dependencies & gt; & Lt; Dependency & gt; & Lt; Group & gt; Javax.servlet & lt; / Group & gt; & Lt; ArtifactId & gt; JSTL & lt; / ArtifactId> & Lt; Version & gt; 1.2 & lt; / Edition & gt; & Lt; / Dependencies & gt; & Lt; Dependency & gt; & Lt; Group & gt; Commons-Logging & lt; / Group & gt; & Lt; ArtifactId & gt; Commons-Logging & lt; / ArtifactId> & Lt; Version & gt; 1.1.3 & lt; / Edition & gt; & Lt; / Dependencies & gt; & Lt; / Dependencies & gt;
Controller
package com.jwlayug.controller; Import org.springframework.stereotype.Controller; Import org.springframework.ui.model; Import org.springframework.web.bind.annotation.RequestMapping; @Controller Public Class ControllerA {@RequestMapping (value = "/ Hello") public string printHello (model model) {model.addAttribute ("message", "spring"); System.out.println ("This method is called!"); Return "hell"; }}
Config
package com.jwlayug.config; Import org.springframework.context.annotation.Bean; Import org.springframework.context.annotation.ComponentScan; Import org.springframework.context.annotation.configuration; Import org.springframework.web.servlet.config.annotation.EnableWebMvc; Import org.springframework.web.servlet.view.JstlView; Import org.springframework.web.servlet.view.UrlBasedViewResolver; @Configuration // Specifies this class as Marx configuration // to scan @ComponentScan package ("com.jwlayug") // Announcement of spring @ EnableWebMvc public class configuration {@Bean Public UrlBasedViewResolver setupViewResolver () {UrlBasedViewResolver Resolver = New UrlBasedViewResolver (Enables); Resolver.setPrefix ("/ web-INF / views /"); Resolver.setSuffix ("jsp."); Resolver.setViewClass (JstlView.class); Return resolver; }} Package com.jwlayug.config; Import javax.servlet.ServletContext; Import javax.servlet.ServletException; Import javax.servlet.ServletRegistration.Dynamic; Import org.springframework.web.WebApplicationInitializer; Import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; Import org.springframework.web.servlet.DispatcherServlet; Public class WebInitializer applies WebApplicationInitializer {Public Zero onStartup (ServletContext ServletContext) ServletException {AnnotationConfigWebApplicationContext ctx = New AnnotationConfigWebApplicationContext throws (); Ctx.register (Config.class); Ctx.setServletContext (ServletContext); Dynamic servlet = universalcontact.edervelet ("sender", new dispatcher circlet (CTX)); Servlet.addMapping ("/"); Servlet.setLoadOnStartup (1); }}
jsp
& lt;% @ page language = "Java" contentType = "text / html; charset = ISO-8859-1" PageEncoding = "ISO-8859-1"%> & Lt;% @ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%> & Lt ;! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 Transcription // N" "http://www.w3.org/TR/html4/loose.dtd"> & Lt; Html & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = ISO-885 9-1" & gt; & Lt; Title & gt; Insert title here & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; $ {Message} & lt; C: out value = "$ {message}" /> & Lt; / Body & gt; & Lt; / Html & gt;
$ {message}
is not a valid syntax JSP is out of an EL expression that you have & lt; C: out / & gt;
is in.
Please
Comments
Post a Comment