I am simply trying to send a new .jsp page to be rendered by the client using the URIBuilder. So I have a main.js send a POST to the server which calls logIn(). For now I just want this to send a new .jsp file to the client to be rendered. Nothing happens thus far, I have tried using different file paths - before I just used "Feed.jsp" as the file path.
I feel like there is more to this that I am not picking up on.
Here is my main.js file. It sends a POST to server successfully via the logIn() method. This main.js is used successfully by my index.jsp file.
var rootURL = "http://localhost:8080/messenger/webapi";
$(function() {
$('#btnRegister').click(function() {
var username = $('#username').val();
registerProfile();
});
$('#btnSignIn').click(function() {
logIn();
});
function logIn() {
var profileJSON = formToJSON();
$.ajax({
type: 'POST',
contentType: 'application/json',
url: rootURL + "/profiles/logIn",
dataType: "json",
data: profileJSON,
success: (function(data){
alert("Success!");
})
});
}
function registerProfile() {
var profileJSON = formToJSON();
$.ajax({
type : 'POST',
contentType: 'application/json',
url: rootURL + "/profiles",
dataType: "json",
data: profileJSON,
success: (function() {
alert("Resgistered");
})
});
}
function formToJSON() {
return JSON.stringify({
"profileName": $('#username').val(),
"password" : $('#password').val(),
});
}
});
Here is my is the method LogIn() called in my ProfileResource.java. It successfully can call the post but for some reason when I include the UriBuilder it does nothing.
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@POST
@Path("/logIn")
public Response logIn( @Context ServletContext context) {
UriBuilder uriBuilder = UriBuilder.fromUri(URI.create(context.getContextPath()));
uriBuilder.path("Deployed Resources/webapp/Feed.jsp");
URI uri = uriBuilder.build();
return Response.seeOther(uri).build();
}
}
So basically my index.jsp gets rendered to the client. My "btnResgister" button does what it needs, my "btnSignIn" just doesn't do anything although I know it accesses the "profiles/login" resource fine.
Update
I have implemented my login method like this using user peeskillets UriUtils
class:
@POST
@Path("/logIn")
public Response logIn( @Context ServletContext context, @Context UriInfo uriInfo) {
URI contextPath = UriUtils.getFullServletContextPath(context, uriInfo);
UriBuilder uriBuilder = UriBuilder.fromUri(contextPath);
uriBuilder.path("Feed.jsp");
return Response.seeOther(uriBuilder.build()).build();
}
But the POST
is still not being completed. I am wondering if this has to do with the ServletContext or UriInfo parameters... Are these parameters automatically sent when I POST
or do I have to send more info from the client using .js
?
Also here is my file structure: