1

Can i send object or bean instead of sending parameters in jsp request to servlet, if yes , How can i get the value from each input field and use it inside jsp.

E.g:

//define user object
<jsp:useBean id="user" class="iug.edu.entities.UserBean"/>
//here is the input inside fomr
<input type="text" name="userName"/>
//here jsp code , to add object attributes
   <%
            user.setFullName**(?????**);  // how can i get userName from input field
   %>

i can make it via java script but can i use js var inside jsp ? what should i do ??plz help!

brabster
  • 42,504
  • 27
  • 146
  • 186
palAlaa
  • 9,500
  • 33
  • 107
  • 166
  • 1
    Similar question: http://stackoverflow.com/questions/3868307/binding-form-parameters-to-a-bean-using-just-servlets-and-jsp-possible – BalusC Oct 06 '10 at 04:02
  • Many thanx Mr BlausC , u really help me learning jsp and servlet concepts ,thaaaaaanx , tonight i'll try to make it with jsp bean and i hope it works properly. – palAlaa Oct 06 '10 at 19:47

2 Answers2

4

No, you can't. JSP is evaluated on the server side, and you want client interaction. With HTTP clients can send data to server-side components only via request parameters (strings)

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • what should i do if i want to send unkown parameters numebr for each time jsp page run ? i was thinking of using list but what can i do now? – palAlaa Oct 04 '10 at 17:34
  • 1
    you have `request.getParameterMap()` which you can iterate. – Bozho Oct 04 '10 at 17:39
0

for sending complex parameter you can use JSON. put your parameter in JSON formatted in client side and get it as JSON object in server. Good thing about JSON is there are good libraries for JSON in js and java. for more about it you can read JSON.ORG

Saeed
  • 616
  • 1
  • 6
  • 16