开发者

send object from JSP to sevlet [duplicate]

开发者 https://www.devze.com 2023-01-18 21:18 出处:网络
This question already has answers here: Passing an object from JSP page back to Servlet (3 answers) Closed 7 years ago.
This question already has answers here: Passing an object from JSP page back to Servlet (3 answers) Closed 7 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消