Sie sind auf Seite 1von 14

document.

write(' ADMINISTRACIONSITEMA <%-Document : AdministracionSistema Created on : 17-may-2011, 13:39:43 Author : yesy --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>bienvenido ala administracion de la biblioteca</h1> <html:form action="Libros"> isbn<html:text property="Isbn"/><br> Titulo<html:text property="Titulo"/><br> Autor<html:text property="Autor"/><br> Editorial<html:text property="Editorial"/><br> <html:submit value="Insertar"/> </html:form><html:errors /> </body> </html>

LOGIN

<%-Document : Login Created on : 17-may-2011, 13:41:11 Author : yesy --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Inicio del Sistema</h1> <html:form action="Login"> Nombre <html:text property="name"/> Password <html:password property="pass"/><br> <html:submit value="login"/> </html:form><html:errors/> </body> </html> EXITOSA <%-Document : exitosa Created on : 17-may-2011, 13:40:24 Author : yesy --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Se inserto exitosamente</h1> </body> </html>

WELCOME STRUTS <%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %> <html:html lang="true"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title><bean:message key="welcome.title"/></title> <html:base/> </head> <body style="background-color: white"> <logic:notPresent name="org.apache.struts.action.MESSAGE" scope="application"> <div style="color: red"> ERROR: Application resources not loaded -- check servlet container logs for error messages. </div> </logic:notPresent> <h3><bean:message key="welcome.heading"/></h3> <p><bean:message key="welcome.message"/></p> </body> </html:html>

LOGICA LIBROS

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Logica; /** * * @author Alumno */ public class Libro { String isbn; String titulo; String autor; String editorial;

public Libro() { } public Libro(String isbn, String titulo, String autor, String editorial) { this.isbn = isbn; this.titulo = titulo; this.autor = autor; this.editorial = editorial; } public String getAutor() { return autor; } public void setAutor(String autor) { this.autor = autor; } public String getEditorial() { return editorial; } public void setEditorial(String editorial) { this.editorial = editorial; } public String getIsbn() { return isbn; } public void setIsbn(String isbn) { this.isbn = isbn; } public String getTitulo() { return titulo; } public void setTitulo(String titulo) { this.titulo = titulo; } @Override public String toString() { return "Libro{" + "isbn=" + isbn + "titulo=" + titulo + "autor=" + autor + "editorial=" + editorial + \'}\'; }

TRANSACCIONES BDMANAGER

/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Transacciones; import Logica.Libro; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Alumno */ public class BdManager { static Connection conn; static { try { Class.forName("com.mysql.jdbc.Driver"); conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/escuela"); } catch (Exception ex) { Logger.getLogger(BdManager.class.getName()).log(Level.SEVERE, null, ex); } } public boolean ValidarUser(String name, String pass) { try { Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from usuarios where name=\'" + name + "\' and pass=\'" + pass + "\'"); if (rs.next()) {

return true; } else { return false; } } catch (SQLException ex) { Logger.getLogger(BdManager.class.getName()).log(Level.SEVERE, null, ex); return false; } } public boolean InsertarLib(Libro lib){ try { PreparedStatement pstmt = conn.prepareCall("insert into libro values(?,?,?,?)"); pstmt.setString(1, lib.getIsbn()); pstmt.setString(2, lib.getTitulo()); pstmt.setString(3, lib.getAutor()); pstmt.setString(4, lib.getEditorial()); int res =pstmt.executeUpdate(); if(res <=0) return false; else return true; } catch (SQLException ex) { Logger.getLogger(BdManager.class.getName()).log(Level.SEVERE, null, ex); return false; } } }

APPLICATIONRESOURSE # -- standard errors -errors.header=<UL> errors.prefix=<LI><span style ="color:red"> errors.suffix=</LI></span> errors.footer=</UL> # -- validator -errors.invalid={0} is invalid. errors.maxlength={0} can not be greater than {1} characters. errors.minlength={0} can not be less than {1} characters. errors.range={0} is not in the range {1} through {2}. errors.required={0} is required. errors.byte={0} must be an byte. errors.date={0} is not a date.

errors.double={0} must be an double. errors.float={0} must be an float. errors.integer={0} must be an integer. errors.long={0} must be an long. errors.short={0} must be an short. errors.creditcard={0} is not a valid credit card number. errors.email={0} is an invalid e-mail address. # -- other -errors.cancel=Operation cancelled. errors.detail={0} errors.general=The process did not complete. Details should follow. errors.token=Request could not be completed. Operation is not in sequence. # -- welcome -welcome.title=Struts Application welcome.heading=Struts Applications in Netbeans! welcome.message=It\'s easy to create Struts applications with NetBeans. error.name.required=Necesitas ingresar un nombre de usuario error.pass.required=Necesitas ingresar un password error.userpass.invalid=Nombre y password Incorrectos error.isbn.required=Ingresa un ISBN error.titulo.required=Ingresa un Titulo error.autor.required=Ingresauna Editorial error.badInsert=El libro no pudo ser insertado correctamente

LIBROS STRUTS ACTION /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.myapp.struts; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * * @author Alumno */ public class LibroStrutsAction extends org.apache.struts.action.Action {

/* forward name="success" path="" */ private static final String SUCCESS = "OpLibros"; /** * This is the action called from the Struts framework. * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing. * @param response The HTTP Response we are processing. * @throws java.lang.Exception * @return */ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward(SUCCESS); } }

LIBROSTRUCTACTIONFORM /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.myapp.struts; import Logica.Libro; import Transacciones.BdManager; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; /** * * @author Alumno */ public class LibroStrutsActionForm extends org.apache.struts.action.ActionForm { private String name; private String isbn;

private String titulo; private String autor; private String editorial; private int number; public String getAutor() { return autor; } public void setAutor(String autor) { this.autor = autor; } public String getEditorial() { return editorial; } public void setEditorial(String editorial) { this.editorial = editorial; } public String getIsbn() { return isbn; } public void setIsbn(String isbn) { this.isbn = isbn; } public String getTitulo() { return titulo; } public void setTitulo(String titulo) { this.titulo = titulo; } /** * @return */ public String getName() { return name; } /** * @param string */ public void setName(String string) {

name = string; } /** * @return */ public int getNumber() { return number; } /** * @param i */ public void setNumber(int i) { number = i; } /** * */ public LibroStrutsActionForm() { super(); // TODO Auto-generated constructor stub } /** * This is the action called from the Struts framework. * @param mapping The ActionMapping used to select this instance. * @param request The HTTP Request we are processing. * @return */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); Libro lib = new Libro(); lib.setIsbn(getIsbn()); lib.setTitulo(getTitulo()); lib.setAutor(getAutor()); lib.setEditorial(getEditorial()); BdManager bd = new BdManager(); if (getIsbn() == null || getIsbn().length() < 1) { errors.add("name", new ActionMessage("error.isbn.required")); // TODO: add \'error.name.required\' key to your resources } if (getTitulo() == null || getTitulo().length() < 1) { errors.add("name", new ActionMessage("error.titulo.required")); // TODO: add \'error.name.required\' key to your resources

} if (getAutor() == null || getAutor().length() < 1) { errors.add("name", new ActionMessage("error.autor.required")); // TODO: add \'error.name.required\' key to your resources } if (getEditorial() == null || getEditorial().length() < 1) { errors.add("name", new ActionMessage("error.Edit.required")); // TODO: add \'error.name.required\' key to your resources } if (!bd.InsertarLib(lib)) { errors.add("name", new ActionMessage("error.badInsert")); // TODO: add \'error.name.required\' key to your resources } return errors; } }

LOGIN STRUTS ACTION /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.myapp.struts; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; /** * * @author Alumno */ public class LoginStrutsAction extends org.apache.struts.action.Action { /* forward name="success" path="" */ private static final String SUCCESS = "success"; /** * This is the action called from the Struts framework. * @param mapping The ActionMapping used to select this instance. * @param form The optional ActionForm bean for this request. * @param request The HTTP Request we are processing.

* @param response The HTTP Response we are processing. * @throws java.lang.Exception * @return */ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { return mapping.findForward(SUCCESS); } } LOGINSTRUTSACTIONFROM /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.myapp.struts; import Transacciones.BdManager; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; /** * * @author Alumno */ public class LoginStrutsActionForm extends org.apache.struts.action.ActionForm { private String name; private String pass; private int number; public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; }

/** * @return */ public String getName() { return name; } /** * @param string */ public void setName(String string) { name = string; } /** * @return */ public int getNumber() { return number; } /** * @param i */ public void setNumber(int i) { number = i; } /** * */ public LoginStrutsActionForm() { super(); // TODO Auto-generated constructor stub } /** * This is the action called from the Struts framework. * @param mapping The ActionMapping used to select this instance. * @param request The HTTP Request we are processing. * @return */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); BdManager bd = new BdManager(); if (getName() == null || getName().length() < 1) { errors.add("name", new ActionMessage("error.name.required"));

// TODO: add \'error.name.required\' key to your resources } if (getPass() == null || getPass().length() < 1) { errors.add("pass", new ActionMessage("error.pass.required")); // TODO: add \'error.name.required\' key to your resources } if (!bd.ValidarUser(getName(), getPass())) { errors.add("userpass", new ActionMessage("error.userpass.invalid")); // TODO: add \'error.name.required\' key to your resources } return errors; } }

Das könnte Ihnen auch gefallen