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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

RequestDispatcher not working in Servlet.

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

index.html


RegisterServlet.java


web.xml
 
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?)
 
Sourabh Chavan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

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
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

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. "
 
Ron McLeod
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Sourabh Chavan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

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.
 
Ron McLeod
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sourabh Chavan
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.


So, how to fix?
I am new to servlets
 
Ron McLeod
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Ron McLeod
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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:



Can you help me about ,y form problem?
 
Ron McLeod
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Paul Clapham
Sheriff
Posts: 28331
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 4646
582
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic