send object from JSP to sevlet [duplicate]
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 开发者_StackOverflow中文版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!
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)
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
精彩评论