Package edu.dartmouth.cs.gae_sample

Source Code of edu.dartmouth.cs.gae_sample.AddServlet

package edu.dartmouth.cs.gae_sample;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import edu.dartmouth.cs.gae_sample.data.Contact;
import edu.dartmouth.cs.gae_sample.data.ContactDatastore;

public class AddServlet extends HttpServlet {
  private static final long serialVersionUID = 1L;

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {
    String id = req.getParameter("id");
    String tema = req.getParameter("tema");
    String titulo = req.getParameter("titulo");
    String resumen = req.getParameter("resumen");
    String autorind = req.getParameter("autorind");
    String autor1 = req.getParameter("autor1");
    String autor2 = req.getParameter("autor2");
    String autor3 = req.getParameter("autor3");
    String autor4 = req.getParameter("autor4");
    String autor5 = req.getParameter("autor5");
    String autor6 = req.getParameter("autor6");
    String afiliacion = req.getParameter("afiliacion");
    String unal = req.getParameter("unal");
    String institucion = req.getParameter("institucion");
    String cargo = req.getParameter("cargo");
    String dia = req.getParameter("dia");
    String mes = req.getParameter("mes");
    String anio = req.getParameter("anio");
    String lugar = req.getParameter("lugar");
    String fecha = req.getParameter("fecha");
    String nombre = req.getParameter("nombre");
    String editorial = req.getParameter("editorial");
    String ubicacion = req.getParameter("ubicacion");
    String acceso = req.getParameter("acceso");
    String importancia = req.getParameter("importancia");
    String observ = req.getParameter("observ");
    String ambiental = req.getParameter("ambiental");
    String bienestar = req.getParameter("bienestar");
    String democracia = req.getParameter("democracia");
    String formacion = req.getParameter("formacion");
    String invest = req.getParameter("invest");
    String legado = req.getParameter("legado");
    String megat = req.getParameter("megat");
    String nalPub = req.getParameter("nalPub");
    String territ = req.getParameter("territ");

   
    if (id == null || id.equals("")) {
      req.setAttribute("_retStr", "invalid input");
      getServletContext().getRequestDispatcher("/query_result.jsp")
          .forward(req, resp);
      return;
    }

    Contact contact = new Contact(id, tema, titulo, resumen, autorind, autor1, autor2, autor3, autor4, autor5, autor6, afiliacion, unal, institucion, cargo, dia, mes, anio, lugar, fecha, nombre, editorial, ubicacion, acceso, importancia, observ, ambiental, bienestar, democracia, formacion, invest, legado, megat, nalPub, territ);

    boolean ret = ContactDatastore.add(contact);
    if (ret) {
      req.setAttribute("_retStr", "Add contact " + id + " succ");

      ArrayList<Contact> result = new ArrayList<Contact>();
      result.add(contact);
      req.setAttribute("result", result);
    } else {
      req.setAttribute("_retStr", id + " exists");
    }

    getServletContext().getRequestDispatcher("/query_result.jsp").forward(
        req, resp);
  }

  public void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws IOException, ServletException {
    doGet(req, resp);
  }

}
TOP

Related Classes of edu.dartmouth.cs.gae_sample.AddServlet

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.