0

i am already starting using Spring framework and already i came across some kind of stupid problem ( but in fact i can't solve it) I have controller which looks like:

package org.springframework.rest;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class SomeController {

    @RequestMapping(value = "/", method = RequestMethod.GET)
    @ResponseBody
    public String returnHtmlPage() {

        return "page";

    }

}

where page is page.jsp:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>Home</title>
</head>
<body>
<h1>
    Hello world!  
</h1>

<P>  The time on the server is ${serverTime}. </P>
</body>
</html>

but insteed of HTML file i have only string "page" returned. How can i fix the problem?

2
  • 4
    remove the @ResponseBody :) So are you creating a REST service or a Web App? Commented Nov 16, 2012 at 14:34
  • i cannot believe it! almost 1,5h spent on this! thanks you Boris ! About question, right now i am discovering Spring framework, after this i will try to create REST service Commented Nov 16, 2012 at 14:36

2 Answers 2

1

your code would print out just "page" (because of @ResponseBody). It does not return web page for you. you can use "ModelAndView" instead of "String" as your method output. And set your jsp page name (=page) there. something like this:

@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView returnHtmlPage(){
    ModelAndView model = new ModelAndView("page");
                /* here you can put anything in 'model' object that you
                   want to use them in your page.jsp file */
    return model;
}
Sign up to request clarification or add additional context in comments.

Comments

0

This video will walk you through all the steps to build a RESTFul service using Spring MVC and then consume it using jQuery.http://pluralsight.com/training/Courses/TableOfContents/springmvc-intro You need to have the ContentNegotiatingViewResolver configured correctly as well.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.