hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Need help to create a Servlet
Reply

Forum Jump

Need help to create a Servlet

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
Newbie
 
Join Date: Mar 2003
Posts: 23

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>&nbsp;</p>
<p>&nbsp;</p>
<table width="55%" border="1" align="center">
<tr>
<td width="50%"><%=sOutput %></td>
<td width="50%"><%=sOutput2 %></td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>



Sponsored Links
Reply

Related posts from TheWhir.com
Title Type Date Posted
Cirrus Hosting Lets Users Create Virtual Private Networks within Public Cloud Web Hosting News 2014-05-02 12:40:36
eApps Hosting Listing 2013-12-26 15:43:18
1&1 Internet Adds New SMB Tools to MyWebsite Web Hosting News 2013-03-25 16:29:43
Study Finds New Zealand Cloud Adoption Slow as Enterprises Cite Data Sovereignty, Latency Issues Web Hosting News 2012-11-28 13:15:42
Web Host Rackspace Introduces Cloud Network Isolation Technology Web Hosting News 2012-10-30 11:35:37


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?