response.sendRedirect() and jsp:forward()

Sir,

I want to pass the variable 'transfer' to 3.jsp. What should I do?. And how?

By using both the option like jsp:forward and response.sendRedirect(), its not working. Why? Can't I do it like this?

Here's my code:

<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@ page contentType="text/html;charset=windows-1252"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>

<title>2</title>

</head>

<body>

<%

String name=request.getParameter("name");

String pwd=request.getParameter("pwd");

session.setAttribute("name",name);

String transfer="Teeth";

out.println("<input type=text name=location value=Kolkata maxlength=12 size=12/>");

//response.sendRedirect("3.jsp?action=love");

%>

<jsp:forward page="3.jsp">

</jsp:forward>

</body>

</html>

Thanking you.

[1364 byte] By [Zorama] at [2007-11-27 11:31:47]
# 1

Look in your server logs. Big chance that you see IllegalStateExceptions.

BalusCa at 2007-7-29 16:41:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Yes Sir,

What does it mean?

Zorama at 2007-7-29 16:41:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Look to the message, is it look like "Response already committed" ?

If so, then rearrange your code logic so that *no* data is written to the response yet before invoking the response.sendRedirect() or the jsp:forward. Even no HTML or blank lines.

Better way is to gently use a servlet for this instead of doing that in JSP.

BalusCa at 2007-7-29 16:41:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Ok Sir,

Thanks a lot

Zorama at 2007-7-29 16:41:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...