Need help to create a Servlet
Hi guys,
I use the JSP code below to select stuff from a databse and display it in html.
Ideally I would like to do all the logice stuff in a servlet and display in the jsp page. I aint have a clue about servlets I keep on running into trouble. Could someone help me please!!!!
Also I don't want to use out.println in the servlet.
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<%@ include file ="dbconnect.jsp" %>
<%
//********SPORTS*************
String myQuery ="SELECT * FROM news_item WHERE source = 'Football365 UK' OR source = 'BBC Sports - Football' OR source = 'Sportinglife - Football' OR source = 'Eurosport.com: Football' OR source = 'Ananova: Sport' OR source = 'Google Sports News' ORDER BY date ASC ";
ResultSet rs = mystatement.executeQuery(myQuery);
String sTitle = "";
String sLink = "";
String sOutput = "";
String sDate = "";
String sSource = "";
for (int i=0; i<2; i++)
{
while (rs.next())
{
sTitle = rs.getString("title");
sLink = rs.getString("link");
sDate = rs.getString("date");
sSource = rs.getString("source");
sOutput = sOutput+"<a href="+sLink+">"+sTitle+"</a><br>"+sDate+"<br>"+sSource+"<p>";
}
}
//********WORLD NEWS*************
String myQuery2 ="SELECT * FROM news_item WHERE source = 'AlterNet: War on Iraq' ORDER BY date ASC ";
ResultSet rs2 = mystatement.executeQuery(myQuery2);
String sTitle2 = "";
String sLink2 = "";
String sOutput2 = "";
String sDate2 = "";
String sSource2 = "";
while (rs2.next())
{
sTitle2 = rs2.getString("title");
sLink2 = rs2.getString("link");
sDate2 = rs2.getString("date");
sSource2 = rs2.getString("source");
sOutput2 = sOutput2+"<a href="+sLink2+">"+sTitle2+"</a><br>"+sDate2+"<br>"+sSource2+"<p>";
}
%>
<body bgcolor="#FFFFFF" text="#000000">
<font size="1"></font>
Welcome IE Explorer User
<p> </p>
<p> </p>
<table width="55%" border="1" align="center">
<tr>
<td width="50%"><%=sOutput %></td>
<td width="50%"><%=sOutput2 %></td>
</tr>
</table>
<p> </p>
<p> </p>
</body>
</html>