/* Copyright (c) SEMM NL All rights reserved.
Author : Paul Hamaker. Part of JavaLessons.com
This code is for educational purposes only. Use at own risk.*/

1. import javax.servlet.http.*; 

2. import javax.servlet.*; 

3. import java.io.*; 

4. import java.util.*; 

5.  

6. public class ServDue extends HttpServlet 

7.

8.   public void 

9.   doPost ( HttpServletRequest req, HttpServletResponse resp ) 

10.     throws ServletException, IOException 

11.   { 

12.     String fname =   req.getParameter ( "firstname" ) ; 

13.     String chosen = req.getParameter ( "radiogroup" ) ; 

14.     String[] chosenoptions = req.getParameterValues ( "optionlist" ) ; 

15.  

16.     resp.setContentType ( "text/html" ) ; 

17.  

18.     PrintWriter out = resp.getWriter(); 

19.  

20.     out.println ( "<HTML>" ) ; 

21.     out.println ( "<HEAD>" ) ; 

22.      out.println ( "<TITLE>" ) ; 

23.     out.println ( "Servlets 2" ) ; 

24.     out.println ( "</TITLE>" ) ; 

25.      out.println ( "</HEAD>" ) ; 

26.      out.println ( "<BODY>" ) ; 

27.  

28.     out.print ( "First name : " ) ; 

29.     if ( fname != null

30.         out.println ( fname  + "<BR>" ) ; 

31.  

32.     out.print ( "Radio-button chosen : " ) ; 

33.     if ( chosen != null

34.         out.println ( chosen  + "<BR>" ) ; 

35.  

36.     out.print ( "Option(s) chosen : " ) ; 

37.     if ( chosenoptions != null

38.       out.print( "<UL>" ); 

39.       for ( int i=0; i < chosenoptions.length; i++  ) 

40.         out.println ( "<LI>" + chosenoptions[i] ) ; 

41.  

42.     out.println ( "</BODY>" ) ; 

43.     out.println ( "</HTML>" ) ; 

44.  

45.     out.flush (); 

46.     out.close (); 

47.   } 

48.

49. ======  /formpost.html in servtest2.war =============== 

50. <HTML

51. <TITLE

52. Servlets 2 FORM 

53. </TITLE

54. <BODY

55.  

56. <FORM ACTION="http://localhost:8080/servtest2/srdue" 

57.  METHOD="POST"

58.   

59. First name : 

60. <INPUT TYPE="TEXT" NAME="firstname" MAXLENGTH="30"

61.  

62. Spiritual 

63. <INPUT TYPE="RADIO" NAME="radiogroup" VALUE="spirit" CHECKED

64. Physical 

65. <INPUT TYPE="RADIO" NAME="radiogroup" VALUE="physic"

66.  

67. <BR

68. <SELECT NAME="optionlist" SIZE="4" MULTIPLE

69. <OPTION VALUE="Seth" SELECTED>Seth 

70. <OPTION VALUE="Jane" >Jane 

71. <OPTION VALUE="Robert" >Robert 

72. <OPTION VALUE="Ruburt" >Ruburt 

73. </SELECT

74. <INPUT TYPE="SUBMIT" VALUE="Send"

75.  

76. </FORM

77.  

78. </BODY

79. </HTML

80. =========== WEB-INF/web.xml  in  servtest2.war  ========== 

81. .... 

82.     <servlet> 

83.         <servlet-name>Sdue</servlet-name> 

84.         <servlet-class>ServDue</servlet-class

85.     </servlet> 

86.  

87.     <servlet-mapping> 

88.         <servlet-name>Sdue</servlet-name> 

89.         <url-pattern>/srdue</url-pattern> 

90.     </servlet-mapping> 

91. .... 

92. ====== META-INF/application.xml  in  webapps.ear  ========== 

93. <application> 

94.   <display-name>SEMM's examples</display-name> 

95.  

96.   <module> 

97.     <web> 

98.       <web-uri>servtest.war</web-uri> 

99.       <context-root>/semmun</context-root> 

100.     </web> 

101.   </module> 

102.  

103.   <module> 

104.     <web> 

105.       <web-uri>servtest2.war</web-uri> 

106.       <context-root>/semmdos</context-root> 

107.     </web> 

108.   </module> 

109. </application> 

110. ========================== 

111. http://localhost:8080/semmdos/srdue 

112. http://localhost:8080/servtest2/srdue 

113. http://localhost:8080/semmun/sruno?cnr=4 

114. ========================== 

115. webapps.ear 

116.    servtest.war 

117.       .... 

118.    servtest2.war 

119.       formpost.html 

120.       WEB-INF 

121.          web.xml 

122.          classes 

123.              ServDue.class 

124.    META-INF 

125.         application.xml 

126.  

127.