Title: forwarding a request from servlet to jsp giving blank page in firefox
Tags: java;jsp;firefox;google-chrome;servlets
Question: I have a Login servlet which takes username, password from a form (via POST) on my login page.
Once authenticated, i am trying to navigate to the welcome page. But the problem is, my code works fine on IE8 but on Firefox and Chrome it just displays a blank page.
If I click on view source, all correct HTML is there but nothing is actually displayed.
If I directly request the welcome page from the address bar it is displayed correctly both in FF and chrome.
Posting my code below, please advise any changes/best practises as necessary... this is all new to me.
Login Servlet
public class Login extends HttpServlet {
public static String jsessionid = null;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
System.out.println("GET CALLED");
doPost(req, resp);
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException, ServletException {
System.out.println("POST CALLED");
String username = req.getParameter("username");
String password = req.getParameter("password");
String jsessionid_full;
String endpoint = "https://sample-url";
try {
// Authentication Code...
// Authentication Code...
// resp.sendRedirect(resp.encodeRedirectURL("welcome.jsp"));
String nextJSP = "welcome.jsp";
RequestDispatcher dispatcher = getServletContext()
.getRequestDispatcher(nextJSP);
dispatcher.forward(req, resp);
} catch (Exception e) {
System.out.println(e);
}
The welcome.jsp page is currently just some static text
My web.xml is ...
<?xml version="1.0" encoding="UTF-8"?&gt;
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
<display-name&gt;mobile CRM</display-name&gt;
<servlet&gt;
<servlet-name&gt;Login</servlet-name&gt;
<servlet-class&gt;crmApp.Login</servlet-class&gt;
</servlet&gt;
<servlet-mapping&gt;
<servlet-name&gt;Login</servlet-name&gt;
<url-pattern&gt;/Login</url-pattern&gt;
</servlet-mapping&gt;
<servlet&gt;
<servlet-name&gt;AccountQuery</servlet-name&gt;
<servlet-class&gt;crmApp.AccountQuery</servlet-class&gt;
</servlet&gt;
<servlet-mapping&gt;
<servlet-name&gt;AccountQuery</servlet-name&gt;
<url-pattern&gt;/AccountQuery</url-pattern&gt;
</servlet-mapping&gt;
<welcome-file-list&gt;
<welcome-file&gt;login.jsp</welcome-file&gt;
</welcome-file-list&gt;
</web-app&gt;
My Authentication procedure works fine... its only the display of the welcome page that is having problems in FF and chrome.
Also after the execution the URL in the address bar is of the Login servlet ie /Login
Any response would be appreciated.
Thanks
Comment: You don't need to worry about which browser you're using.


Here is another answer: Take a look at the http headers coming back. There are some good ff plugins to show these eg Live http headers
Compare the headers retuned from your login-forward request to those for your direct welcome page request.

Here is another answer: sorry... the problem was apparently in one of my stylesheets
using jQuery and jQuerymobile in here... browser issues!

Here is another answer: I don't know why you're seeing different behavior in different browsers with a forward since it's internal to the webapp, but try redirecting the user instead of forwarding; that'll cause the URL in the address bar to change as well.
Here's some good info on the subject.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 3, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:05/04/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><jsp><firefox><google-chrome><servlets>', 'Title': 'forwarding a request from servlet to jsp giving blank page in firefox', 'ViewCount': 5599, 'id': 10456506, 'user_AboutMe': None, 'user_AccountId': 31667.0, 'user_DisplayName': 'Vic', 'user_Reputation': 336.0, 'user_Views': 125.0, 'user_id': 87150.0}}