• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

help---please

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi-- I don't know if i have just been staring at this too long but I am so frusterated i could cry....

I have an html form the user selects the type of sear(last name, first name, dept etc) and in a text box the user types in what are looking for then the user submits the page..

I have a class called EmployeeAddressSearchResultsServlet which displays the requested information in a table

The search is done against an access database

I don't know how to get the search to send the information and put it into the table. I do know that i am supose to loop and have the information feed in and create the table.

The instructor said to do it with a servlet and a javabean...
can anybody point me in the right direction.

I have the basic structure of the pages
[code]

<html>
<head>
<title> Employee Address Book Search </title>
</head>
<body bgcolor = #33FFCC>
<h1 align = center> Search the Employee Address Book</h1>
<p>Employee Address Book:</p>
<p>To look an employee up by their last name </p>
<form action="/servlet/java146.project3.EmployeeAddressSearchResultsServlet" method="Get\">
<br /><input type="radio" name="empSearch" value="findListById">Employee Id
<br /><input type="radio" name="empSearch"value="findListByLastName">
Employee Last Name
<br /><input type="radio" name="empSearch"
value="findListByFirstName">Employee First Name
<br /><input type="radio" name="empSearch" value="findListByDept">Employee
Department Name
<br /><input type="text" name="search" SIZE="40" MAXLENGTH="40">
<br /><p align = center>
<input type = "submit" name = "submitButton" value = "Search">
<input type = "reset" name = "resetButton" value = "Reset">
/p>
<h4><a href =" ../index.html"> Back to Home Page</a></h4>
</form>
</body>
</html>

package java146.project3;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java146.util.*;

/**
* Description of the Class
*@author VBrandt
*@created November 24, 2004
*/
public class EmployeeAddressSearchResultsServlet extends HttpServlet
{
//Connection connects = null;
/**
* Description of the Method
*@exception ServletException Description of the Exception
*/
public void init() throws ServletException {}

/**
* Description of the Method
*@param req Description of the Parameter
*@param res Description of the Parameter
*@exception ServletException Description of the Exception
*@exception IOException Description of the Exception
*/
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.print("<html>");
out.print("<head>");
out.print("<title>Results Page</title>");
out.print("<h1 align = center>Search Results</h1>");
out.print("</head>");
out.print("<table border = 1 cellpadding = 2 align = center >");
out.print("<th>ID</th> <th>Last Name</th> <th>First
Name</th> <th>Department</th>");
out.print("<tr>");
out.print("<td> </td>");
out.print("<td> </td>");
out.print("<td> </td>");
out.print("<td> </td>");
out.print("</tr>");
out.print("</table>");
out.print("<p>");
out.print("<h4 align = center><a href =../index.html>
Back to Home Page</a>" +
"\t<a href =../EmpAddressPage.html> \t
Search again</h4></a>");
out.print("<BODY>");
out.print("</body>");
out.print("</html>");
}
}
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you have so far for your JavaBean?
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A suggestion to make your life a bit easier -

Do not use a Servlet to output HTML. Prepare the data to be displayed in a String[], 'String' List, a HashMap or a custom JavaBean, pass it to the JSP as a request attribute, and use the JSP to output the HTML.

This also makes it easier for other people to help you because you can post smaller amount of code that focusses on the problem at hand.
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to move this to the Java in General (intermediate) forum, because a discussion of servlets is really beyond a "beginner" forum.
 
Valarie Brandt
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to the specs for the project I have to use the static html page for the user to enter the information from there I am confused.
are servlet java bean going to be a separate file? I thought i was suppose to it in one page.
 
Sonny Gill
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do it all on one page, but that gets very difficult to manage and debug.

Your input form seems fine at a cursory glance.

One way of implementing the functionality would be this -

Have an EmployeeAddress bean with fields for the address info, and the getter and setter methods, This is a simple Value Object or Data Transfer Object. Its purpose is only to pass data from one part of your program (the Servlet) to another part (the JSP you will use to display the result).

Have an EmployeeManager class which can lookup the address info, given the search criteria, and return an EmployeeAddress populated with the information retrieved.

Now, in your java146.project3.EmployeeAddressSearchResultsServlet, you can have something like.



Have a JSP, which uses the EmployeeAddress set by the servlet to display it to the user. Here you place the HTMl that you were earlier trying to generate from the Servlet.

It will access the EmployeeAddress object set in the Servlet as follows



HTH. Refer to the Java API documentation for detailed information on the classes in javax.servlet package.
[ December 05, 2004: Message edited by: Sonny Gill ]
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would use the html you have for input. The servlet gets the input from the html page and passes the information it gets to the Java bean (a plain old java object type of class -- nothing special -- probably the type of class you've been working with all along).

The Java bean does the work and returns the results to the servlet (the return value of the method call) which then forwards the results to a JSP or html page.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic