wood burning stoves 2.0*
The moose likes Java in General and the fly likes help---please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "help---please " Watch "help---please " New topic
Author

help---please

Valarie Brandt
Greenhorn

Joined: Oct 03, 2003
Posts: 24
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>");
}
}
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
What do you have so far for your JavaBean?


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

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.


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
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

Joined: Oct 03, 2003
Posts: 24
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

Joined: Feb 02, 2002
Posts: 1211

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

Joined: Jul 22, 2000
Posts: 9044
    
  10
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help---please
 
Similar Threads
form data
not getting responce from Servlet
File not found error
calling a method in jsp
javax.servlet.ServletException: PWC1381: Error allocating a servlet instance