Reputation: 176
I'm trying to pass parameter to jsp to servlet. And my code is :
Server side :
String kullanici = (String)request.getParameter("onaylayici");
JSP side :
<input type="text" name ="onaylayici">
When i run it on localhost kullanici
variable comes null
. Any solution ?
EDİT :
<form name = "main" method = "POST">
<td class="summary"><b>İsteği Onaylanacak Kişi :
<input type="text" name ="onaylayici"> <br>
</form>
Upvotes: 0
Views: 3981
Reputation: 1
< input type="text" name ="onaylayici" value="<% if(kullanici!=null){out.print(request.getAttribute(kullanici))} %>">
<% /Hope this helps!/%>
Upvotes: 0
Reputation: 1261
Don't know why but it worked for me when I provided 'name' attribute to input text.
My Old code which returned null in Servlet:
<input id="closure" type="text" size="25"><a
href="javascript:NewCal('closure','ddmmyyyy')"><img
src="drawables/cal.gif" width="16" height="16" border="0"
alt="Pick a date"></a>
Just putting name="closure" worked for me. Now it perfectly returns value of this input text into servlet.
<input id="closure" name="closure" type="text" size="25"><a
href="javascript:NewCal('closure','ddmmyyyy')"><img
src="drawables/cal.gif" width="16" height="16" border="0"
alt="Pick a date"></a>
And I am getting value of this input text in Servlet as follows:
String closure = request.getParameter("closure");
Upvotes: 0
Reputation: 6525
Your code is ok, but a small mistake . You have not set the request data to the response page. So, You have to set the requested data to response as follow:-
Change on Server Side -
//Get the data from JSP
String myDataInServer = (String)request.getParameter("onaylayici");
//Set the data to response by request.setAttributes
request.setAttributes("onaylayici",myDataInServer);
JSP (Client Side )-
String kullanici = (String)request.getParameter("onaylayici");
Now it will work. Hope it will help you.
Upvotes: 0
Reputation: 1146
I think you mean that you want to go FROM a jsp TO a servlet. If that's the case, look the action attribute:
<form action='/MyServlet' ...>
...
</form>
If you are going FROM a Servlet TO a jsp then you could reuse current request attribute. You do it by settng the value directly in the . Something similar to this:
request.setAttribute("onaylayici", request.getParameter("onaylayici"));
in your servlet. Then, in your jsp this:
<input name='onaylayici' type='text' value='${requestScope["onaylayici"]}'/>
Upvotes: 1
Reputation: 176
My solution is :
<input name='onaylayici' type='text' value='${requestScope["onaylayici"]}'/>
Note : Thanks fGo ...
Upvotes: 0
Reputation: 3833
If you want to set your parameter value in Servlet
and read it in JSP
, then you need to do the following:
In Servlet
:
request.setAttribute("yourParamName", request.getParameter("yourParamValue"));
and in your JSP
:
<input name='yourParamName' type='text' value="<%=request.getAttribute("yourParamName")%>" />
Upvotes: 0
Reputation: 7
There are only form's name and method, without the action, the JSP don't know where to send its arguments, and the server can't receive the arguments too. For example:
<form action="/servlet/Test" method="post">
...
</form>
Upvotes: 0