SearchScheduleServlet.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:4k
源码类别:
Java编程
开发平台:
Java
- package slsbsample;
- /*
- *
- * Copyright 2001, 2002 JavaCamp.com, Inc. All Rights Reserved.
- *
- * Grant the rights to the purchaser of the book to use the source code.
- * .
- * @author Pravin Tulachan
- * @version 1.0
- * @see
- * @since
- *
- */
- //package j2eebootcamp.developingEJB.chapter6.web.servlets;
- import java.util.*;
- import java.io.*;
- import java.rmi.RemoteException;
- import java.util.Vector;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import javax.rmi.PortableRemoteObject;
- import javax.naming.InitialContext;
- /*import j2eebootcamp.developingEJB.chapter6.search.Schedule;
- import j2eebootcamp.developingEJB.chapter6.search.ScheduleHome;
- import j2eebootcamp.developingEJB.chapter6.model.ScheduleVO;*/
- //import j2eebootcamp.developingEJB.util.Logger;
- public class SearchScheduleServlet
- extends HttpServlet {
- Schedule remote;
- ScheduleHome home;
- PrintWriter out;
- RequestDispatcher dispatcher;
- public void init() throws ServletException {
- try {
- InitialContext ic = new InitialContext();
- Object objref = ic.lookup("Schedule");
- System.out.println(" == Servlet MySchedule lookup ok");
- home = (ScheduleHome) PortableRemoteObject.narrow(objref, ScheduleHome.class);
- remote = home.create();
- System.out.println(" == Servlet home.create ok");
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void doGet(HttpServletRequest req, HttpServletResponse res) throws
- ServletException, IOException {
- defaultAction(req, res);
- }
- public void displayMessage(HttpServletRequest req,
- HttpServletResponse res,
- String messageText) throws ServletException,
- IOException {
- res.setContentType("text/html");
- out = res.getWriter();
- out.println(messageText);
- }
- public void defaultAction(HttpServletRequest req, HttpServletResponse res) throws
- ServletException, IOException {
- //get a handle to the response object for output
- res.setContentType("text/html");
- /* extract name/value pair from the request object */
- String searchBy = req.getParameter("SearchBy");
- String searchToken = req.getParameter("SearchText");
- Vector vList = new Vector(20);
- try {
- //find out search option and perform search.
- if (searchBy.equals("courseTitle")) {
- vList = (Vector) remote.searchByCourseTitle(searchToken);
- System.out.println(" == Servlet searchByCourseTitle() ok");
- if (vList.isEmpty()) {
- out.println(" == empty vector exiting");
- System.exit(0);
- }
- req.setAttribute("vec", vList);
- System.out.println(" == Servlet - dispatching to JSP ");
- dispatcher = getServletContext().getRequestDispatcher(
- "/ShowSearchResult.jsp");
- }
- else if (searchBy.equals("courseID")) {
- ScheduleVO schedule = null;
- //int courseID = (new Integer(searchToken)).intValue();
- System.out.println("KAO,a little problem!");
- schedule = (ScheduleVO) remote.searchByScheduleID(searchToken);
- System.out.println(" == Servlet searchByScheduleID() ok");
- req.setAttribute("sched", schedule);
- System.out.println(" == Servlet - dispatching to JSP ");
- dispatcher = getServletContext().getRequestDispatcher(
- "/ShowSearchResult1.jsp");
- }
- }
- catch (RemoteException re) {
- re.printStackTrace();
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- dispatcher.forward(req, res);
- }
- }