I’m including some code examples, where I mainly use JSP tags inside of a jsp page for most presentation. I use java classes (beans) for getter/setters and do all database updates and inserts through a class. My question is JSP dead now or is it and will it be still alive.
EXAMPLE EDIT PAGE: I present the data and after the edit, I use ajax to communicate with the page/and bean to update:
<html>
<head>
<script type="text/javascript" src="include/lock.js"></script>
<link rel="stylesheet" href="include/style.css" type="text/plain">
</head>
<body>
<%@ page language="java" import="java.sql.*" %>
<%@ include file = "util.inc" %>
<jsp:useBean id="db" class="SQLBean.DbBean" />
<jsp:setProperty
name="db"
property="petid"
param="petid" />
<%
out.println("the pet id is" + db.getpetid());
String varmv = request.getParameter("mv");
String vart11 = request.getParameter("t11");
String submit = request.getParameter("submit");
if(submit != null)
{
%>
<jsp:setProperty
name="db"
property="petname"
param="petname" />
<jsp:setProperty
name="db"
property="species"
param="species" />
<jsp:setProperty
name="db"
property="sex"
param="sex" />
<jsp:setProperty
name="db"
property="ownerid"
param="ownerid" />
<jsp:setProperty
name="db"
property="petowner"
param="petowner" />
<jsp:setProperty
name="db"
property="ostreet"
param="ostreet" />
<jsp:setProperty
name="db"
property="dogpic"
param="dogpic" />
<%
int ri;
db.connect();
String sql = "UPDATE pets SET petname=?, ownerid=?, petowner=?, species=?, sex=?, ostreet=?, dogpic=? WHERE petid=?";
db.updatepet(sql);
out.println("<a href=trypage3.jsp?mv=" + varmv + "&t11=" + vart11 + ">back</a>");
out.println("<br>");
// out.println("<a href="+session.getAttribute( "reqsess" )+">sessback</a>");
db.close();
}
%>
<%
int vpetid;
vpetid = db.getpetid();
String tmppetid = "";
String tmppetname = "";
String tpic = "";
ResultSet SQLResult = null;
db.connect();
String sql;
sql = "SELECT petid, petname, species, sex, ownerid, petowner, ostreet, dogpic FROM pets where petid = ?";
SQLResult = db.editSQL(sql);
while(SQLResult.next())
{
tmppetid = SQLResult.getString("petid");
tmppetname = SQLResult.getString("petname");
String varpic;
String vspecies;
String vsex;
String vownerid;
String voname;
String vostreet;
if (SQLResult.getString(8) != null && SQLResult.getString(8).length() > 0)
{
varpic = SQLResult.getString(8);
}
else
{
varpic = "";
}
if (SQLResult.getString(3) != null && SQLResult.getString(3).length() > 0)
{
vspecies = SQLResult.getString(3);
}
else
{
vspecies = "";
}
if (SQLResult.getString(4) != null && SQLResult.getString(4).length() > 0)
{
vsex = SQLResult.getString(4);
}
else
{
vsex = "";
}
if (SQLResult.getString(5) != null && SQLResult.getString(5).length() > 0)
{
vownerid = SQLResult.getString(5);
}
else
{
vownerid = "";
// vownerid = convJS(SQLResult.getString(5));
}
if (SQLResult.getString(6) != null && SQLResult.getString(6).length() > 0)
{
voname = SQLResult.getString(6);
}
else
{
voname = "";
}
if (SQLResult.getString(7) != null && SQLResult.getString(7).length() > 0)
{
vostreet = SQLResult.getString(7);
}
else
{
vostreet = "";
}
%>
<table border=0 cellspacing=5 cellpadding=2>
<form name="petsedit" id="petsedit" action="tryedit2.jsp" method="POST">
<tr>
<td>Pet name</td>
<td><input type="Text" name="petname" id="petname" size="20" value="<%=SQLResult.getString(2) %>"></td> </tr>
<tr>
<td>Species</td>
<td><input type="Text" name="species" id="species" size="20" value="<%=vspecies %>"></td> </tr>
<tr>
<td>Sex</td>
<td><input type="Text" name="sex" id="sex" size="20" value="<%=vsex %>"></td> </tr>
<tr>
<td>pet pic</td>
<td><input type="Text" name="dogpic" id="dogpic" size="20" value="<%=varpic %>"></td>
</tr>
<!-- <tr>
<td> </td>
<td> <input type="button" value="Write Back" onclick="WriteBack()"/> </td>
</tr> -->
<tr>
<td>Owner id</td>
<td><input type="Text" name="ownerid" id="ownerid" size="20" value="<%= vownerid %>"> <input type="button" value="Write Back" onclick="WriteBack()"/>
<a href="#" onclick="getowner('1','zoooz','0');" id="idlookup1">find</a></td>
</tr>
<tr>
<td>owner name</td>
<td><input type="Text" name="petowner" id="petowner" size="20" value="<%=voname %>"></td> </tr>
<tr>
<td>ostreet</td>
<td><input type="Text" name="ostreet" id="ostreet" size="20" value="<%=vostreet %>"></td> </tr>
<tr>
<input type="hidden" name="petid" id="petid" value="<%= SQLResult.getInt("petid") %>">
<input type="hidden" name="mv" id="mv" value="<%= varmv %>">
<input type="hidden" name="t11" id="t11" value="<%= vart11 %>">
</form>
</table>
<%
out.println(db.getspecies());
}
out.println("<br>");
out.println("<a href="+session.getAttribute( "reqsess" )+">sessback</a>");
out.println("<a href=\\"#\\" onclick=\\"updatepet('"+tmppetid+"')\\"> [save] </a>");
SQLResult.close();
db.close();
%>
<a href="petsearch.htm">Back to search page</a>
</center>
</body>
</html>
Here is part of my js file showing the ajax call:
function updatepet(petid)
{
petname = document.getElementById('petname').value;
species = document.getElementById('species').value;
sex = document.getElementById('sex').value;
ownerid = document.getElementById('ownerid').value;
petowner = document.getElementById('petowner').value;
ostreet = document.getElementById('ostreet').value;
dogpic = document.getElementById('dogpic').value;
mv = document.getElementById('mv').value;
t11 = document.getElementById('t11').value;
var submit = "submit";
petid = document.getElementById('petid').value;
url = "tryedit2.jsp";
params = "petid=" + petid + "&petname=" + petname + "&species=" + species + "&sex=" + sex + "&ownerid=" + ownerid + "&petowner=" + petowner + "&ostreet=" + ostreet + "&dogpic="+dogpic + "&mv="+mv+ "&t11="+t11+ "&submit="+submit;
var http = getXMLHTTP();
http.open("POST", url, true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
var z000z = '';
} else {
alert("There was a problem while using XMLHTTP:\
" + req.statusText);
}
}
}
http.send(params);
displayPopupDiv2();
}
The class isn’t shown, but it is a typical class with getter/setters, prepared statements for the queries, the db connection, etc.
The util file simply escapes strings.
Are these techniques still ok? I have seen examples of jsf, and so far i do not like jsf.