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.
try this
RequestDispatcher RequetsDispatcherObj =request.getRequestDispatcher("/displayItems.jsp");
RequetsDispatcherObj.forward(request, response);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With