RequestDispatcher always needs a forward slash. So try changing it to the following
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
When you use RequestDispatcher.forward to call another servlet, it is "chain of command."
When a servlet is first called, the response object is fresh and new: its headers have not been set, its buffers are empty, and no data has been written to the client.
However, as soon as either the status code or any of the headers have been written -- or potentially written -- to the client, or when data has been -- or may have been -- written to the body stream, then you may be susceptible to the IllegalStateException error. The problem that this exception is signalling is the new data that you are (or may be) writing is inconsistent with the data that's already been set and then irretrivably sent ("committed") to the client.
Two common variants of this exception are "java.lang.IllegalStateException: Header already sent" and "java.lang.IllegalStateException: Cannot forward as Output Stream or Writer has already been obtained".
"Header already sent" means that one or more headers have been committed to the client, so you can't set that header again.
"Output Stream or Writer has already been obtained" means that since the calling servlet has already called response.getWriter() or response.getOutputStream(), that contaminates the data stream, since the response has been (or may have been) written to already, making it unsuitable for forwarding.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…