I am new to JSTL, could someone please tell me how to convert below JSP and HTML code to full JSTL with no scriptlet in the page?

I'd also be grateful for suggestions about some good resources to learn JSTL and advanced JSP concepts such as JSF and spring with CRUD example.

This is curd example taken from http://javaknowledge.info/?p=478. I took this example because I thought it is 100% JSTL implementation but I was wrong.

My IDE is NetBeans.

<form method="POST" action='UserController' name="frmAddUser">
        <% String action = request.getParameter("action");
            System.out.println(action);
        %>
        <% if (action.equalsIgnoreCase("edit")) {%>
        User Name : <input type="text" name="uname"
                           value="<c:out value="${user.uname}" />" readonly="readonly"/> (You Can't Change this)<br /> 
        <%} else {%>
        User Name : <input type="text" name="uname"
                           value="<c:out value="${user.uname}" />" /> <br />
        <%}%>
        Password : <input
            type="password" name="pass"
            value="<c:out value="${user.password}" />" /> <br /> 
        Email : <input
            type="text" name="email"
            value="<c:out value="${user.email}" />" /> <br /> 

        <% if (action.equalsIgnoreCase("edit")) {%>
        Registration : <input
            type="text" name="dob"
            value="<fmt:formatDate pattern="yyyy/MM/dd" value="${user.registeredon}" />" readonly="readonly"/>(You Can't Change this)  <br />
        <%} else {%>
        Registration : <input
            type="text" name="dob"
            value="<fmt:formatDate pattern="yyyy/MM/dd" value="${user.registeredon}" />" />(yyyy/MM/dd)  <br /> 
        <%}%>
        <input  type="submit" value="Submit" />
    </form>
有帮助吗?

解决方案

There are only two types of scriptles:

  • print the current action into system's out - there is no JSTL alternative
  • if-else statement can be rewritten using

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>        
    <c:choose>
      <c:when test='${ fn:toLowerCase(param.action) eq "edit" }'>
        ...
      </c:when>
      <c:otherwise>
        ...
      </c:otherwise>
    </c:choose>
    

其他提示

Years ago i learnd alot from this videos:

https://www.youtube.com/user/3n3xus/videos

Too bad, its in German and eclipse.

You learn

  1. how to write your own JSTL-Framework.
  2. how to write and navigate in jsf
  3. work with richfaces.
  4. how to work with facelets.
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top