0% found this document useful (0 votes)
57 views7 pages

Examen

The document contains code for a Java web application that allows users to search for and view hardware inventory information. It includes JSP pages for the homepage, search, and results display. It also includes Java classes for the data model (Bean), data access layer (DAO), and servlet to handle requests and pass data between pages. The servlet retrieves search results from the database using the DAO and passes the results to the JSP to display on the page.

Uploaded by

Orlando Pinedo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views7 pages

Examen

The document contains code for a Java web application that allows users to search for and view hardware inventory information. It includes JSP pages for the homepage, search, and results display. It also includes Java classes for the data model (Bean), data access layer (DAO), and servlet to handle requests and pass data between pages. The servlet retrieves search results from the database using the DAO and passes the results to the JSP to display on the page.

Uploaded by

Orlando Pinedo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1

<%--
Document : home.jsp
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<center>
<form name="home">
<table>
<tr>
<td>
<a href="home.jsp">home</a> \ <a href="consultarHW.jsp">consultar hw</a> \ <a
href="<%=request.getContextPath()%>/servHW?op=1">eliminar hw</a>
</td>
</tr>

<tr>
<td>
PORTALLLLL de
<br>
evolution soft
</td>
</tr>
</table>
</form>
</center>
</body>
</html>

--Listado.jsp

<%@page import="java.util.*" %>
<%@page import="BEAN.*" %>

<%!
ArrayList<proBEAN> lista=null;
%>

<%
lista=(ArrayList<proBEAN>)request.getAttribute("lista");
%>
<html>
<head>

</head>
<body>
<center>
<table>
<tr>
<td>HW</td>
<td>STOCK</td>
</tr>
<tr>
<%
for(proBEAN obj:lista)
{
%>
<tr>
<td><%=obj.getHw()%></td>
<td><%=obj.getStock()%></td>
</tr>
<%
}
%>
</tr>
</table>
</center>
</body>
</html>

--consultarHW.jsp

<%@page import="java.util.*" %>
2

<%@page import="BEAN.*" %>

<%!
ArrayList<proBEAN> lista=null;
%>

<%
lista=(ArrayList<proBEAN>)request.getAttribute("lista");
%>
<html>
<head>
<script>
function buscar()
{
document.home1.action="<%=request.getContextPath()%>/servConsulta";
document.home1.op.value="1";
document.home1.submit();
}

</script>

</head>
<body>
<center>
<form name="home1">
<table>
<tr>
<td>
<a>home</a> \ <a>consultar hw</a> \ <a>eliminar hw</a>
</td>
</tr>

<tr>
<td>CRITERIO DE BUSQUEDA</td>
</tr>

<tr>
<td>NOMBRE</td>
<td><input type="text" name="txtnombre"></td>
</tr>

<tr>
<td>CATEGORIA</td>
<td><select name="cat">
<option value="MOUSE">MOUSE</option>
<option value="DD">disco duro</option>
</select></td>
</tr>
</table>
<table>
<tr>
<td>
<input type="hidden" name="op">
<input type="button" value="BUSCAR" onclick="buscar()">
</td>
</tr>
</table>


<%
if(lista!=null)
{
%>
<table>
<tr>
<td>HW</td>
<td>STOCK</td>
<td>CATEGORIA</td>
</tr>
<%
for(proBEAN obj1:lista)
{
%>
<tr>
<td><%=obj1.getHw()%></td>
<td><%=obj1.getStock()%></td>
<td><%=obj1.getCat()%></td>
</tr>
<%
3

}
%>
</table>
<%
}
%>

</form>
</center>
</body>
</html>

--BEAN

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package BEAN;

/**
*
* @author UNFV-FIIS
*/
public class proBEAN {
String hw,cat;

public String getCat() {
return cat;
}

public void setCat(String cat) {
this.cat = cat;
}

public String getHw() {
return hw;
}

public void setHw(String hw) {
this.hw = hw;
}

public int getStock() {
return stock;
}

public void setStock(int stock) {
this.stock = stock;
}
int stock;

}

--DAO

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package DAO;

import BEAN.proBEAN;
import java.util.*;
import java.sql.*;
import BEAN.*;
import UTIL.*;

/**
*
* @author UNFV-FIIS
*/
public class proDAO {
Connection cn=null;
PreparedStatement pt=null;
ResultSet rs=null;

ArrayList<proBEAN> lista=null;

4

proBEAN objproBEAN=null;

public ArrayList<proBEAN> buscar(proBEAN objproBEAN) {

try {
String nombre=objproBEAN.getHw();
String cat=objproBEAN.getCat();
ConexionBD obj=new ConexionBD();
cn=obj.getConexionBD();
pt=cn.prepareStatement("select * from producto where hw=? and categoria=?");
pt.setString(1, nombre);
pt.setString(2, cat);
rs=pt.executeQuery();
lista=new ArrayList<proBEAN>();
while(rs.next())
{
objproBEAN=new proBEAN();
objproBEAN.setHw(rs.getString(1));
objproBEAN.setCat(rs.getString(2));
objproBEAN.setStock(rs.getInt(4));
lista.add(objproBEAN);
}
} catch (Exception e) {
}
return lista;
}

public ArrayList<proBEAN> buscar2() {
try {

ConexionBD obj=new ConexionBD();
cn=obj.getConexionBD();
pt=cn.prepareStatement("select * from producto");

rs=pt.executeQuery();
lista=new ArrayList<proBEAN>();
while(rs.next())
{
objproBEAN=new proBEAN();
objproBEAN.setHw(rs.getString(1));
objproBEAN.setCat(rs.getString(2));
objproBEAN.setStock(rs.getInt(4));
lista.add(objproBEAN);
}
} catch (Exception e) {
}
return lista;
}

}

--SERVLET
--servConsulta.java
package SERVLET;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.sql.*;
import BEAN.*;
import DAO.*;
import UTIL.*;
/**
*
* @author UNFV-FIIS
*/
public class servConsulta extends HttpServlet {

/**
* Processes requests for both HTTP
* <code>GET</code> and
* <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
5

* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


proBEAN objproBEAN=null;
proDAO objproDAO=null;

String cat,nombre,pagina="";
int stock;

ArrayList<proBEAN> lista=null;

int op=Integer.parseInt(request.getParameter("op"));

switch(op)
{
case 1:
{
cat=request.getParameter("cat");
nombre=request.getParameter("txtnombre");

objproBEAN=new proBEAN();
objproBEAN.setHw(nombre);
objproBEAN.setCat(cat);

objproDAO=new proDAO();
lista=objproDAO.buscar(objproBEAN);
request.setAttribute("lista", lista);
pagina="/consultarHW.jsp";
break;
}
}

getServletContext().getRequestDispatcher(pagina).forward(request, response);
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP
* <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP
* <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
6

}

--servHW.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package SERVLET;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.sql.*;
import BEAN.*;
import DAO.*;
import UTIL.*;
/**
*
* @author UNFV-FIIS
*/
public class servHW extends HttpServlet {

/**
* Processes requests for both HTTP
* <code>GET</code> and
* <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


proBEAN objproBEAN=null;
proDAO objproDAO=null;

String cat,nombre,pagina="";
int stock;

ArrayList<proBEAN> lista=null;

int op=Integer.parseInt(request.getParameter("op"));

switch(op)
{
case 1:
{

objproDAO=new proDAO();
lista=objproDAO.buscar2();
request.setAttribute("lista", lista);
pagina="/listado.jsp";
break;
}
}

getServletContext().getRequestDispatcher(pagina).forward(request, response);
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP
* <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
7

processRequest(request, response);
}

/**
* Handles the HTTP
* <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}

You might also like