Tuesday, 15 July 2014

java - JSP output plain text in Web Browser -


I am using Eclipse, Spring MVC, Maven and Tomcat. It is shown in the index.jsp web browser as shown below. It is not render properly

Any ideas what is wrong?

  index.jsp & lt;% @ page language = "java" contentType = "text / html; charset = ISO-8859-1" page encoding = "ISO-885 9-1" % & Gt; & 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; & Lt; H1 & gt; Index & lt; / H1> & Lt; / Body & gt; & Lt; / Html & gt; @Controller Public Class HelloController {@RequestMapping ("/ greeting") is the public string () {System.out.println ("greeting"); Return "Hello"; } @RequestMapping ("/") public string index () {System.out.println ("index page"); Return "index"; }}  

A controller has a GET and a post request Method.However a At the quick glance, you need to change @RequestMapping ("/ greeting") on @RequestMapping (value = "/ greeting") for your JSP file / src / main / webapp / WEB-INF / view by default (Spring MVC Starter Project)

When you return the string - Spring MVC will look for JSP with that JSP. . So in this example you only want to greet. JSP

  @controller public class greeting controller {/ ** * GET * / @RequestMapping (value = "/ greeting", method = RequestMethod.GET ) Public string handle () {// This URL will be used when retrieving "greeting"; } / ** * POST * / @RequestMapping (value = "/ greeting", method = RequestMethod.POST) Submit Public String Process () {// When you post URL / TODO, it will be used here and Do something you will get back to your page in "Greeting"; }}  

Go ahead and comment if you have any other questions, check my account for my other example

Hope this will be helpful. !

Just a note is the most requested method in spring, but the most used in understanding GAT and Post is used.


No comments:

Post a Comment