The preceding code is rather "complicated", isn't it ?
YES, and it's for this reason JSP were invented: rather than writing html in Java, write Java into html. The file extension is then .jsp
and Java code is put into <% here %>
.
- Swapping Java and HTML (JSP)
The preceding code can be re-written using JSP as follow:
cat > UMS.jsp <<EOF
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.*"%>
<%
ArrayList<String>users = new ArrayList<String>();
users.add("bill");
users.add("kate");
%>
<html>
<head>
<title>UMS</title>
<link rel="stylesheet" href="./static/template.css">
</head>
<body>
<h1>Users Management System</h1>
<ul>
<li><b>Name </b></li>
<% for (String user : users) { %>
<li> <%=user%> </li>
<% } %>
<li><form action="./Users" method="POST">
<input name="name"></input>
<button>add</button>
</form></li>
</ul>
</body>
</html>
EOF
Now, the application is available at:
http://127.0.0.1:8080/web/UMS.jsp
8 - 16Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented
Java jva jav laurent thiry uha enseignant ensisa ecole school national alsace programmation objet approche mulhouse france java object programming oriented