Here is a copy of the jsp page and the servlet....
JSP PAGE
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta http-equiv="Expires" content="0">
<title>Employee List</title>
</head>
<body>
Employee List
<jsp:include page="/servlet/EmployeeList" flush="true" />
</body>
</html>
List Servlet
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class EmployeeList extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
HttpSession session = request.getSession(true);
response.setIntHeader("Expires",0);
response.setHeader("Cache-Control","no-cache");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String Logon = session.getAttribute("Logon").toString();
String Level = session.getAttribute("Level").toString();
if (Logon.compareTo("TRUE") == 0);
else
{
out.println("No Access");
return;
}
if (Level.compareTo("A") == 0);
else
{
out.println("No Access you need to be an Admin");
return;
}
String query = "SELECT EmployeeID, LastName, Firstname FROM
employees order by lastname";
out.println("<TABLE BORDER=1>");
out.println(" <TR>");
out.println(" <TD COLSPAN=4 ALIGN=CENTER><a
href=\"/skills/EmployeeAdd.jsp\">Add New Employee</a></TD>");
out.println(" </TR>");
out.println(" <TR>");
out.println(" <TD>EmployeeID</TD>");
out.println(" <TD>Lastname</TD>");
out.println(" <TD>Firstname</TD>");
out.println(" <TD>Commands</TD>");
out.println(" </TR>");
try
{
Connection dbconn;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
dbconn =
DriverManager.getConnection("jdbc:odbc:ADB");
Statement statement = dbconn.createStatement();
ResultSet rs = statement.executeQuery( query );
while(rs.next())
{
String empid = rs.getString(1);
out.println(" <TR>");
out.println(" <TD>" + empid +
"</TD>");
out.println(" <TD>" +
rs.getString(2) + "</TD>");
out.println(" <TD>" +
rs.getString(3) + "</TD>");
out.println(" <TD><a
href=\"/servlet/EmployeeP?Process=D&EmpID=" + empid + "\">Delete</a>
Edit</TD>");
out.println(" </TR>");
}
}
catch ( Exception excp )
{
// process remaining Exceptions here
excp.printStackTrace();
out.println(excp.toString());
}
out.println("</TABLE>");
}
}
Process Servlet gets called on delete and add form sens data to this servlet
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class EmployeeP extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
Connection dbconn;
String Process = request.getParameter("Process");
String query = "";
if (Process.equals("D"))
{
String EmpID = request.getParameter("EmpID");
query = "DELETE FROM Employees WHERE EmployeeID = "
+ EmpID;
}
if (Process.equals("A"))
{
String Lastname = request.getParameter("Lastname");
String Firstname =
request.getParameter("Firstname");
query = "INSERT INTO Employees " +
"(FirstName,Lastname) " +
"VALUES (" +
"'" + Firstname + "'" +
"," + "'" + Lastname + "'" + ")";
}
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader("Expires",0);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
out.println(query);
dbconn =
DriverManager.getConnection("jdbc:odbc:ADB");
Statement statement =
dbconn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDA
TABLE);
int result = statement.executeUpdate( query
);
if (result == 1)
{
int ct = (int) (Math.random()*1000);
response.sendRedirect("/skills/EmployeeList.jsp");
}
else
{
out.println("Error");
}
}
catch ( Exception excp )
{
// process remaining Exceptions here
excp.printStackTrace();
out.println(excp.toString());
}
}
}
-----Original Message-----
From: JustinMacCarthy [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 08, 2000 9:37 AM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: RE: $20 bucks to the 1st person who actually solves my
problem!!!
Hi David , are you using any meta tags in the HTML you are spitting out. You
should use the meta cache tags , to ensure fresh content.
Email me if you need the syntax.
Justin
>-----Original Message-----
>From: Adress, David S. [mailto:[EMAIL PROTECTED]]
>Sent: Friday, December 08, 2000 1:29 PM
>To: JRun-Talk
>Subject: $20 bucks to the 1st person who actually solves my problem!!!
>
>
>I am on this for days and I can't figure out what I'm doing wrong. I will
>send $20 bucks to 1st person who actually solves my problem.
>
>I am using jsp page's to control the layout of my page and servlets to spit
>back
>table data or to do database transactions.
>
>I have a jsp page that displays a list of employees. The jsp page
>has an include statement to include the servlet to spit out the table.
>The jsp just handles the general look of the page and the servlet just
>spits out the table and table html tags. Next to each record I have an add
>and
>delete hyperlink. If someone clicks the add link it displays
>another page to
>add
>an employee and then the action servlet adds the record and then goes back
>to the jsp
>list page. If some one deletes a record it calls a servlet to delete and
>then the servlet redirects back to the jsp list page. But the list doesn't
>display the updated data without having me hit the refresh button in the
>browser.
>
>I tried using Tomcat and now am using Jrun and am still having the same
>problem.
>
>I've included all the proper meta tags in the jsp list page not to
>cache but
>it's not working. I've also tries doing it with reponse.setHeader but it
>doesn't work either.
>
>I've tried sending a random number param to the page
>ShowList?rnd=Randomnumber it still doesn't work.
>
>
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Your ad could be here. Monies from ads go to support these lists
>and provide more resources for the community.
http://www.fusionauthority.com/ads.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Your ad could be here. Monies from ads go to support these lists and provide more
resources for the community. http://www.fusionauthority.com/ads.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists