I've got a page where the user inputs information into a form and then hits submit. When the submit button is clicked the user POST's data to a java file. I'm using 开发者_开发技巧out.print()
to print Strings but how would I POST an object when the HTML form is submitted?
<form action="/myServlet">
<input name="uid" type="text" value="testUser"/>
<input name="pwd" type="password" value="mypwd" />
<input name="myObj" type="hdden" value="<%=someObject%>">
<input type="submit" />
</form>
If there is any form like this, when user clicks on submit button. form will be submitted to the action url "/myServlet" . here action is servlet or nay action. we can get the data from the serverside by using request.getParameter("myObj");
When submit is clicked the request will go to a servlet.
In servlet the form data can be obtained.
Check this example Simple Servlet example
If an object has to be passed from jsp then DWR can be used for this purpose.
Here I gave an explanation of how to do in DWR
Some tutorials for DWR
精彩评论