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?
            Asked
            
        
        
            Active
            
        
            Viewed 2,932 times
        
    0
            
            
         
    
    
        Skizit
        
- 43,506
- 91
- 209
- 269
- 
                    What object do you want to pass from jsp page? – lukastymo Sep 26 '11 at 20:10
- 
                    One I've created which contains some Strings and Int's – Skizit Sep 26 '11 at 20:17
- 
                    4http://stackoverflow.com/questions/4253660/passing-object-from-jsp-to-servlet – Bhesh Gurung Sep 26 '11 at 20:19
- 
                    @Skizit, Bhesh has given you very useful link. Try it ;) – lukastymo Sep 26 '11 at 20:25
- 
                    I'm not sure if I understand the question. Do you want to pass a Java(bean) object unmodified around between requests, or do you want to set all submitted parameters of the form in a new Java(bean) object? If the former, then Bhesh has given the correct exact dupe question. If the latter, check this question instead: http://stackoverflow.com/questions/5096454/easy-way-of-populating-javabeans-based-on-request-parameters – BalusC Sep 26 '11 at 20:34
2 Answers
1
            
            
            <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");
 
    
    
        Satya
        
- 8,146
- 9
- 38
- 43
0
            
            
        - 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. 
 
    
    
        Community
        
- 1
- 1
 
    
    
        Srikanth Venkatesh
        
- 2,812
- 1
- 20
- 13