Servlet web hosting - JavaSercer Pages All radio button elements have the

December 31, 2006 on 8:19 pm | In Java |

JavaSercer Pages All radio button elements have the name language, which means that they form a group where only one of them can be selected. When the user clicks on the Submit button, the same page is requested with the value of the selected radio button included as a request parameter named language. As described above, this triggers the action to switch to the selected language. Next comes another form with radio buttons representing the three possible answers to the poll question. As you can see, both the question and the answers are displayed in the selected language. When the user selects an answer and clicks on the button to submit a vote, the calculate.jsp page shown in Example 11.2 is invoked. Example 11.2. Validation and Calculation of Votes (calculate.jsp) <% if (answer.isValid( )) { %> <% } else { %> <% } %> As with all pure logic pages, this page contains only actions and a few simple scriptlets; no response text is generated. A PollBean in the application scope is used to keep track of the answers from all visitors, and an AnswerBean in the page scope captures and validates a single answer. The AnswerBean has one property named answer, which is set to the value of the corresponding request parameter using the action. It also has an isValid( ) method, used in a scriptlet to test if the answer is valid or not. In this example, it returns true if the answer ID is valid (1, 2, or 3). However, in a real application you may want to include other validation rules. For instance, if the poll information was stored in a database, you could use cookies or a username to make sure each user answers only once. If the answer is valid, a action is used to set the answer property of the PollBean to the valid answer, and the request is forwarded to the result.jsp page to display the poll statistics. Figure 11.3 shows a sample of the result page with the Swedish locale. Figure 11.3. The result page using the Swedish locale page 156

Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Sandzak.com j2ee web hosting services

No Comments yet

TrackBack URI

Sorry, the comment form is closed at this time.