A. Here is the servlet.
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
UserService userService = UserServiceFactory.getUserService();
String thisUrl = req.getRequestURI();
resp.setContentType("text/html");
if (req.getUserPrincipal() != null) {
//code
} else {
resp.getWriter().println("<p>Please <a href=\""
+ userService.createLoginURL(thisUrl)
+ "\">sign in</a>.</p>");
System.out.println("no user registered");
//req and resp is OK at server, as in "Eclipse console" can print "no user registered"
}
return;
}
Ajax.util.js
var signIn = function(){
$.ajax({
url : "/users",
type : "GET",
data: "",
success : function(resp) {
var datum='';
datum=resp.data;
var htm='';
htm+='<p>Please <a href=\'' +datum +'\'>sign in with google account</a>.</p>';
$('#'+'demo').html(htm);
}});}
//Result : index.html is able to display the link at id="demo", but UNDEFINED link (error 404)
//Suppose: to give a link for user to "sign in with google account"
//from this Google method ::: userService.createLoginURL(thisUrl)
Thank you