Simpanoz
Simpanoz

Reputation: 2859

How to print text in web browser by using Play 2 framework

I am newbie to Play 2 framework. How can I print 'HELLO WORLD' text in web browser without using any view file.

I have setup route file as below :

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET /                        controllers.Mantra.index()

# Map static resources from the /public folder to the /assets URL path
GET     /assets/*file               controllers.Assets.at(path="/public", file)

My controller is as below:

package controllers;

import play.*;
import play.mvc.*;
import play.data.*;
import play.data.validation.Constraints.*;

import java.util.*;
import views.html.*;


public class Mantra extends Controller  {


  public static Result index(){
     return ok(index.render("HELLO WOLRD"));

  }

}

I have tried many times, but it is still showing default page. Can some one guide what Iam doing wrong and how it can be rectified.

Thanks in advance

Upvotes: 0

Views: 660

Answers (2)

biesior
biesior

Reputation: 55798

It displays always welcome page, because in your views/index.scala.html file you have still this line:

@play20.welcome(message, style = "Java")

It loads the welcome page from the Play. After removing it you can start using this view, as your any other view.

Of course for displaying saute text nico_ekito's solution is better, than rendering it via views.

Upvotes: 0

ndeverge
ndeverge

Reputation: 21564

Use:

public static Result index(){
     return ok("HELLO WORLD");

}

ie, call the ok() method which take only a String as parameter.

Upvotes: 4

Related Questions