Nothing happens when my Servlet use RequestDispatcher.forward
My servlet:
request.setAttribute("mB", mB);
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
try {
rd.forward(request, response);
} catch (ServletException|IOException e) {
e.printStackTrace();
}
The file index.jsp
is in my WebContent folder, but the index.jsp
is not forwarded when I call the Servlet.
My project structure:
my web.xml:
<servlet>
<servlet-name>Servlet</servlet-name>
<servlet-class>logic.Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet</servlet-name>
<url-pattern>/servlet</url-pattern>
</servlet-mapping>
How can I resolve this problem?
How can I get information from forward
error? I try to debug and I found that the rd
has a requestURI
value that coincides with MyProject/index.jsp
that is the URI that I want.
EDIT: My Servlet is called by a JavaScript page, not how I say first. This is the js function:
function onSignIn(googleUser) {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/MyProject/servlet');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send('idtoken=' + id_token + '&page=' + window.location.href);
}
EDIT 2: I think the problem is the Google Sign-in button that I use to call the js file.
<div class="googleLogin" id="signin-container">
<div class="g-signin2" data-onsuccess="onSignIn"></div>
</div>
<div class="googleLogout" id="signout-container">
<h4 class="font"><a href="#" onclick="signOut();">Sign out</a></h4>
</div>