Issue
I'm calling a JSP, displayItems.jsp
from a servlet, DataPortal.java
. First I tried to do this using the RequestDispatcher
like this,
String url = "/displayItems.jsp";
ServletContext context = getServletContext();
RequestDispatcher dispatcher = context.getRequestDispatcher(toDo);
dispatcher.forward(req, res);
well... the control did go to the JSP page, however it printed the entire contents of the JSP file (including tags and everything) instead of displaying as a webpage. Next I tried to achieve this by using response.sendRedirect(url);
and this time it gives me an empty page. What am I doing wrong here? The JSP is like this,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<script src="http://jqueryjs.googlecode.com/files/jquery-1.3.js" type="text/javascript"></script>
</head>
<body>
<div>i am in display category</div>
</body>
</html>
Any help is appreciated.
Solution
The problem is solved. This is how: I had a DispatchServlet calling the DataPortal which in turn was calling the displayItems.jsp. The reason dispatcher.forward was not working in DataPortal was because i was doing dispatcher.include in DispatchServlet to call the DataPortal. When i changed this to forward, things started working. So thank you guys, for your response.
Answered By - sherry
Answer Checked By - Willingham (JavaFixing Volunteer)