I have eclipse project (Using MyBatis and Jersey) which controls "Login page". Jersey services create two different pages, where you can see string output about events (for ex.: login created, creation error, wrong data and so on). But how can I transfer this string from java code into HTML page:
//some fancy looking HTML form
<div class="header">
<h1>Login Form</h1>
<span>Some text which I want to extract from String.</span>
</div>
//form continues
Jersey class which can create two different pages at this moment (with only string output):
package qLogin.rest;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import qLogin.validator.*;
@Path("/")
public class LoginInfo {
@POST
@Path("/logged")
@Consumes("application/x-www-form-urlencoded")
@Produces(MediaType.TEXT_HTML)
public Response LogIn(
@FormParam("email") String email,
@FormParam("password") String password//,
/*@Context UriInfo uriInfo*/) {
LoginValid loginValid = new LoginValid(email, password);
String output = loginValid.getHtmlAnswer();
return Response.status(200).entity(output).build();
}
@POST
@Path("/create")
@Consumes("application/x-www-form-urlencoded")
public Response newCreate(
@FormParam("email") String email,
@FormParam("password") String password) {
CreateValid createValid = new CreateValid(email, password);
String output = createValid.Outputter();
return Response.status(200).entity(output).build();
}
}
To build html page i can use following code:
URI uri = uriInfo.getBaseUriBuilder().path("/test.html").build();
return Response.seeOther(uri).build();
But how do I put String output into this page?
If you want to do it server-side, you could use a templating framework/engine and produce the expected HTML output during a call to a custom MessageBodyWriter.