-1

i am trying to set the value using request attribute in jsp , i am trying to get the value in servlets using request.getAttribute(), but request.getAttribute() is giving null value

this is my code in jsp:

<form action="action.do" enctype="multipart/form-data" method="post" onsubmit="return submit_form()">

<input type="hidden" name="id" parameter="id" value="<%=id%>" >
request.setAttribute("validTillDate",validtilldate);

in Servlets:

String vaidTillDate=(String)request.getAttribute(validTillDate);
System.out.println("date is:"+validTillDate)  // output is : date is : null
chakri
  • 629
  • 3
  • 11
  • 21
  • Should use <% request.setAttribute("validTillDate",validtilldate); %>...right? – Wand Maker Jul 03 '13 at 12:49
  • I'm not sure, but i think that you can't set an attribute in a jsp. – TroyAndAbed Jul 03 '13 at 12:53
  • Look at this question: http://stackoverflow.com/questions/229937/using-request-setattribute-in-a-jsp-page – TroyAndAbed Jul 03 '13 at 12:54
  • 1
    Why don't you just add another hidden input field like you already did for the ID? What were you thinking/expecting? I'd suggest to learn basic HTTP as well, lifecycle of HTTP request/response and so on. This will improve your understanding of "under the covers" working of JSP/Servlet. – BalusC Jul 03 '13 at 12:54
  • @TroyAndAbed i got some trouble with that link. In place of hidden what type i should use – chakri Jul 03 '13 at 13:02
  • @BalusC I have two attributes to send from jsp to servlets , so it is not possible – chakri Jul 03 '13 at 13:05
  • 1
    If you understood basic HTTP, you'd have realized that it makes no utter sense what you're trying. So, start learning HTTP. – BalusC Jul 03 '13 at 13:09

1 Answers1

2

Try adding another hidden for 'validtilldate'

<input type="hidden" name="id" parameter="id" value="<%=id%>" >
<input type="hidden" name="validtilldate" parameter="validtilldate" value="<%=validtilldate%>" > 
Gnanz
  • 1,833
  • 5
  • 24
  • 51