开发者

POST java object from .jsp to java

开发者 https://www.devze.com 2023-04-07 12:41 出处:网络
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 pr

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

0

精彩评论

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

关注公众号