-1

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?

2 Answers2

0

URI uri = uriInfo.getBaseUriBuilder().path("../example.html/url?stringval=output").build(); return Response.seeOther(uri).build();

Lijo
  • 6,498
  • 5
  • 49
  • 60
  • I've changed it to `URI uri = uriInfo.getBaseUriBuilder().path("/test.html/url?stringval=\"output\"").build();` but as I see, problem in **?** symbol, because I am getting following url: ../test.html/url%3Fstringval="output" – Cockabondy Jan 14 '14 at 11:51
  • Probably you have to set the queryString using another method – everton Jan 14 '14 at 12:26
  • There's two problems with this solution: I need to encode URL, so "?" will be displayed correctly, and "output" string will not be consumed as string anyway. So you're right, going to find another way :) – Cockabondy Jan 14 '14 at 13:41
0

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.

Xavier Coulon
  • 1,580
  • 10
  • 15
  • That's the case. I know that I can rewrite half of my code and create different pages for different situations, so jersey will just create "answerpage.html" But in this case I'd like to know how to transfer exactly this string into html form =) – Cockabondy Jan 14 '14 at 11:45
  • Ok, I understand ;-) Well, can't you put in an entity or as a request attribute and then, inject the request in the `MessageBodyWriter` with the `@Context` annotation ? – Xavier Coulon Jan 14 '14 at 11:52
  • Hmm. Never tried it tho. Thank for tip. Looks like it may be the right solution. – Cockabondy Jan 14 '14 at 11:57