I have a jsp form that takes different inputs from user. How can I print the submitted data on another jsp page?
            Asked
            
        
        
            Active
            
        
            Viewed 2,152 times
        
    1
            
            
        - 
                    Two stage: 1. accept data (and store somewhere: session, database, url, cache) 2. print it. – Jacek Cz Jun 14 '18 at 11:23
- 
                    what is REAL usage? – Jacek Cz Jun 14 '18 at 11:23
2 Answers
0
            In your first JSP page:
<form method="post" action="otherPage.jsp">
   <input type="text" name="firstName">
   <input type="submit" value="Submit">
</form>
then on the otherPage.jsp you can get the value of the input:
<%
    String name = request.getParameter("firstName");
    out.println("Firstname: " + name);
%>
..although using scriptlets is normally discouraged.
If you want to use e.g. Spring MVC you post the form to a Controller which handles the request and there you can pass the parameters forward.
 
    
    
        Jack Flamp
        
- 1,223
- 1
- 16
- 32
- 
                    
- 
                    
- 
                    
- 
                    @Marium then you should have written that in your question. https://stackoverflow.com/help/mcve. Alternatively you can use a web framework, like Spring MVC, J2EE, or anything else.. there are Many!! – Jack Flamp Jun 14 '18 at 10:45
- 
                    Like putting the form data into an object and then printing the data from that object – Marium Jun 14 '18 at 10:46
- 
                    @Marium look [here](https://spring.io/guides/gs/serving-web-content/) or [here](https://www.tutorialspoint.com/spring/spring_web_mvc_framework.htm) – Jack Flamp Jun 14 '18 at 10:48
- 
                    "..although using scriptlets is normally discouraged." Then why post answer which uses technology that went out of fashion in the early 2000s. – Alan Hay Jun 14 '18 at 11:02
- 
                    
- 
                    An answer using JSTL tags or JSP EL to output the data would be more relevant. – Alan Hay Jun 14 '18 at 11:06
0
            
            
        The use of scriptlets in JSP is strongly discouraged:
How to avoid Java code in JSP files?
You can achieve the same using JSP Expression Language (JSP EL):
<p>First name was ${param.firstName}</p>
 
    
    
        Alan Hay
        
- 22,665
- 4
- 56
- 110
