get null in JSP

Hi friends,

i have one page and form method is get .when i m get parameter in next page then getting null but when i m useng post method then getting value.

one.jsp

<form method="get" action="getTask_mobile1.jsp?user=<%=user%>" name="gettaskinmobile">

</form>

second.jsp

<%

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

out.println("user name is--> "+user);

%>

getting null...

where is my problem.? i want to get value..

so please give me reaply..

Thank you,

[576 byte] By [Jayesh_Javaa] at [2007-10-3 3:46:49]
# 1

I assume "getTask_mobil1.jsp" is actually the same as "second.jsp" in your post. If that's the case, then since obviously there is a parameter named "user", then the variable user is not null. It might contain the character string "null", but it is not null.

Try this:

<%

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

if (user == null)

out.println("no user parameter!");

else

out.println("user parameter value is \"" + user + "\", length=" + user.length());

%>

warnerjaa at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...
# 2
ya getTask_mobil1.jsp is the second.jsp but i want value not null..i want user value..if i use same code poset insted of get then get the value..i want to use get method in form and i want to get value..thanks.
Jayesh_Javaa at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...
# 3
Why not post?
corlettka at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...
# 4
bcs in this page parameter must display in url so i did not use post method..
Jayesh_Javaa at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...
# 5

> ya getTask_mobil1.jsp is the second.jsp but i want

> value not null..

> i want user value..if i use same code poset insted of

> get then get the value..

> i want to use get method in form and i want to get

> value..

>

> thanks.

Well, I suspect this is the problem:

> ... action="getTask_mobile1.jsp?user=<%=user%> ..."

That is evaluated on the server side before the page is even rendered to the client, and has nothing to do with whatever "user" value the user fills in the form.

So it probably generated this on page generation:

... action="getTask_mobil1.jsp?user=null ..."

If you insist on using the "GET" method, you'll probably have to write some javascript on the page to dynamically generate the URL the form will 'GET' when the submit button is pressed.

warnerjaa at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...
# 6
hey if i m using like this also got the null valueaction="getTask_mobile1.jsp?user=jayesh..."now i m not useing serverisde then aslo got the null value..
Jayesh_Javaa at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...
# 7
> hey if i m using like this also got the null value> action="getTask_mobile1.jsp?user=jayesh..."> > ow i m not useing serverisde then aslo got the null> value..Then the code you posted is not the code that is actually being run.
warnerjaa at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...
# 8

-->gettask_mobile.jsp(one.jsp)

<%@page contentType="text/html"%>

<%@page pageEncoding="UTF-8"%>

<%

String user = (String) session.getAttribute("loguser");

if(user == null)

response.sendRedirect("login.jsp");

%>

<html>

<head>

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

<title>Task in Mobile</title>

</head>

<body>

<form method="get" action="getTask_mobile1.jsp?user=<%user%>" name="gettaskinmobile">

<%

out.println("User is-->"+user);

task = mobiletask.getTaskinmobile(user);

%>

<input type="submit" name="task" value="Submit">

</form>

</body>

</html>

-->gettask_mobile1.jsp(second.jsp)

<%@page contentType="text/html"%>

<%@page pageEncoding="UTF-8"%>

<%

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

out.println("user name is--> "+user);

%>

Jayesh_Javaa at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...
# 9
Since you're using "GET", perhaps your browser has cached second.jsp (with the matching parameter(s)), so it's not actually re-fetching the page. Investigate putting cache directives on the page as well so that the browser does not do that.
warnerjaa at 2007-7-14 21:43:38 > top of Java-index,Java Essentials,New To Java...