Use JSTL to Check Selected Value From Form Select Option : Form Select « JSTL « Java Tutorial






<html>
<head><title>Select Your Portal</title></head>
<body>
<h1>Select your preferred portal:</h1>
<form action="showportal.jsp" method="get">
<select name="portchoice">
<option>news</option>
<option>weather</option>
<option>entertainment</option>
</select>
<input type="submit" value="Select"/>
</form>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
                           
<html>
 <c:choose>
    <c:when test="${param.portchoice == 'news'}">
      <head><title>News Portal</title></head>
      <body>
       <h1>Welcome to the News Portal!</h1>   
      </body>
    </c:when>
    <c:when test="${param.portchoice == 'weather'}">
       <head><title>Weather Portal</title></head>
       <body>
        <h1>You Get the Latest Weather!</h1>   
       </body>
    </c:when>
    <c:when test="${param.portchoice == 'entertainment'}">
       <head><title>Entertainment Portal</title></head>
       <body>
       <h1>Entertainment News Just for You!</h1>   
       </body>
    </c:when>
    <c:otherwise>
       <head><title>System Portal</title></head>
       <body>
       <h1>Application logic problem detected!</h1>   
       </body>
    </c:otherwise>
</c:choose>
</html>
  Download:  JSTLCheckSelectedValueFromFormSelectOption.zip( 1,561 k)








24.16.Form Select
24.16.1.JSTL Form Select and CheckBox Group
24.16.2.Use JSTL to Check Selected Value From Form Select Option
24.16.3.Add/Remove Form Select Option Item