Jeff
Jeff

Reputation: 1591

New to Spring MVC: Is an html file being created on the fly here?

I am looking at the Spring-Petclinic sample code which uses Spring MVC to display and update/create pet owners, etc. I am confused by the following code fragment in a JSP file:

<spring:url value="/owners.html" var="formUrl"/>
<form:form modelAttribute="owner" action="${fn:escapeXml(formUrl)}" method="get" class="form-horizontal"
           id="search-owner-form">
    <fieldset>
        <div class="control-group" id="lastName">
            <label class="control-label">Last name </label>
            <form:input path="lastName" size="30" maxlength="80"/>
            <span class="help-inline"><form:errors path="*"/></span>
        </div>
        <div class="form-actions">
            <button type="submit">Find owner</button>
        </div>
    </fieldset>
</form:form>

I am wondering if this is trying to create a new file called owners.html because I can't find such a file anywhere in the existing files.

Upvotes: 0

Views: 149

Answers (3)

duffymo
duffymo

Reputation: 308733

JSPs are an HTML templating solution. Here is how it works:

  1. You write a JSP, preferably using only tags and not scriptlet code, and put it in your WAR.
  2. The servlet/JSP engine reads the JSP when you first request its URL, parses it into an abstract syntax tree, and generates Java source.
  3. The servlet/JSP engine compiles the Java source into a .class file, which it then invokes every time it receives a request at that URL.
  4. The compiled JSP dynamically merges data into an output stream that is the HTML sent to the browser on request.

So you may find a generated .java or .class file if you know where to look and have asked that it be saved appropriately, but the HTML only exists on the wire from the server to the client.

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691635

No, it doesn't. The JSP tag <spring:url> is used to define an attribute (named formUrl here) referencing an url (which is /<context-path>/owners.html here).

Upvotes: 1

ACV
ACV

Reputation: 10562

No, it just generates the url poining to that action. In this case the action name is owners.html, look inside controller and you will find it.

Upvotes: 0

Related Questions