Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Intro to Java Web Development with Spark Diving into Web Development Accepting Requests

Tornike Shelia
Tornike Shelia
2,781 Points

The output result doesn't show String , instead it shows : spark.ModelAndView@508e5484

public class Main {
    public static void main(String[] args) {

        get("/", (req, res) -> new ModelAndView(null, "index.hbs"), new HandlebarsTemplateEngine());

        post("/sign-in",(req,res)->{
            Map<String, String> model = new HashMap<>();
            model.put("username" , req.queryParams("username"));
            return new ModelAndView(model,"sign-in.hbs");
        });new HandlebarsTemplateEngine();
    }
    }

sign-in.hbs :

    <body>
      <p>Welcome {{ username }}! </p>
    </body>

When I type anything in the input field it shows : spark.ModelAndView@508e5484 , the numbers are random everytime

1 Answer

Tracy Bowers
Tracy Bowers
6,816 Points

Your syntax is incorrect. I can see why you are bashing your head. Stuff like this is so easy to miss. You have: });new HandlebarsTemplateEngine();

you in fact need: , new HandlebarsTemplateEngine() );

Notice you need to create a lambda and create a new handekbarsTemplateEngine object which are both passed as parameters to the post method.

Your syntax is only passing the lambda because you have a ";" followed by calling for a new HandelbarsTemplateEngine object.

Try not to go cross-eyed. But yes this is really awkward in my opinion. The powers that be in the Java world are trying to make this better... hopefully