Jersey (Jax-RS) & EL
im trying to get the controller to return the view through the Expression language filter but have no idea how to get the jersey to use EL to filter the view.
View with EL tags:
<html>
<title>%{msg}</title>
</html>
Controller:
@GET
@Produces("text/html")
public Response viewEventsAsHtml(){
String view=null;
try {
view=getViewAsString("events");
}catch(IOException e){
LOG.error("unable to load view from file",e);
return null;
}
Response.ResponseBuilder builder=Response.ok(view, MediaType.TEXT_HTML);
return builder.build();
}
How do I do this to force the controller to replace the $ {msg} part in the view with some arbitrary value?
+2
a source to share
1 answer
If you are using Jersey, then it provides the ability to return a view from a resource, which will by default be a jsp process .
Jersey resource example
@Path("/patient")
public class PatientResource {
@GET @Path("/{patientId}") @Produces(MediaType.TEXT_HTML)
public Viewable view(@PathParam("patientId") int patientId) {
return new Viewable("/patient.jsp", Integer.toString(patientId));
}
}
Patient.jsp example
<span>${it}</span>
NOTE. Jersey renders the object you pass as visible as "it" in jsp.
Once you redirect jersey to jsp, you just need to add EL implementation to your app server or servlet container.
+4
a source to share