This week's book giveaway is in the Programmer Certification forum. We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
I am working with a servlet project in which the user inputs data in a form and if the terms and conditions are not met then the form is displayed.
However, the above functionality does not seem to work?
How do I fix it?
Sourabh Chavan wrote:... the above functionality does not seem to work
You will need to provide some details.
What were you expecting, and what did you observe?
I was expecting that when I run the app on netbeans and don't click on terms and conditions agree the browser displays the form with details with the text "the terms and consitions have not been agreed"
Sourabh Chavan wrote:However, the above functionality does not seem to work?
What makes you think that it doesn't work? (Or are you still unsure whether it works or not?)
I was expecting that when I run the app on netbeans and don't click on terms and conditions agree the browser displays the form with details with the text "the terms and consitions have not been agreed. However, the form is displayed without the details I entered. "
Sourabh Chavan wrote:I was expecting that when I run the app on netbeans and don't click on terms and conditions agree the browser displays the form with details with the text "the terms and consitions have not been agreed"
Sourabh Chavan wrote:I was expecting that when I run the app on netbeans and don't click on terms and conditions agree the browser displays the form with details with the text "the terms and consitions have not been agreed"
And what was actually displayed?
However, the form is displayed without the details I entered.
I guess that is because if your check for the conditions being accepted (condition!=null) returns false, then you send back the same static HTML content that you sent originally, which does not include any values.
Ron McLeod wrote:I guess that is because if your check for the conditions being accepted (condition!=null) returns false, then you send back the same static HTML content that you sent originally, which does not include any values.
I haven't worked with Servlets for a while, so I am probably not the best one to answer, but one solution would be to use JSPs (Java Server Pages) and java.lang.EL (Java Expression Language).
Something else I noticed ... I'm assuming that since you are not specifying specific values for for the radio input elements, that you are seeing a value of on for gender, and are unable to distinguish between male/female.
To fix this, modify your existing code:
To include values for male and female:
Or even better, using labels:
Ron McLeod wrote:Something else I noticed ... I'm assuming that since you are not specifying specific values for for the radio input elements, that you are seeing a value of on for gender, and are unable to distinguish between male/female.
To fix this, modify your existing code:
To include values for male and female:
Or even better, using labels:
Sourabh Chavan wrote:Can you help me about ,y form problem?
Sorry - all I can suggest is that if you want to use server-side rendering with dynamic content, then maybe take a look at JSPs. Hopefully others can make better recommendations.
I wouldn't write that code like that either. And I don't know how to run it in Netbeans so you might be doing that wrong or expecting something different than what Netbeans does. But anyway I'd suggest that debugging the Java code would be helpful.
Ron McLeod wrote:I haven't worked with Servlets for a while, so I am probably not the best one to answer, but one solution would be to use JSPs (Java Server Pages) and java.lang.EL (Java Expression Language).
I had some time today so I reworked your project to use JSP and EL. It's not perfect, but it should be good-enough provide an example of how to use JSPs. Reply-back here if you have any questions.
RegisterServlet.java
RegisterData
web.xml
index.jsp
display.jsp
pom.xml
Source tree
She still doesn't approve of my superhero lifestyle. Or this shameless plug:
Gift giving made easy with the permaculture playing cards