简体   繁体   中英

How to dynamically create a form based on submitting the first form

For eg: 1) I have one text box and submit button if a person adds the value and select submit button then this text box value will be sent to java program where internal calculations will be made and returned to the JSP page based on the values new form should be dynamically created on same page and this form should have the value of the text box which is created before and if i submit it should send all the values to java program...

Please post me a sample code of jsp and java program asap

If I'm understanding you correctly this is how your data flow would look like?

HTML Form Data --> Java Servlet --> HTML Data ?

The approach I would, is by using Java Beans to populate your data. They are just normal java class with private fields, getters and setters to store value. Refer here for more information

Form

<form action"YourServlet">
<!-- Your input e.g username and submit button -->
</form>

SERVLET

//request data
//do your calculation
//populate bean
//dispatch to jsp

BEAN

//private field correspond to your form data value e.g userName
//constructor no arg
//getters and setters
//other methods

JSP

<body>
<jsp:useBean id="bean" class="package.BeanClass" scope="session"/>
Value:
<jsp:getProperty name="bean's id" property="property name"/>
</body>

用解决问题的外部Java文件编写了3个jsp:1-第一个jsp 2-第二个jsp 3-决定jsp 4- java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM