I have a controller method as follow.
#RequestMapping("/edit/{jobId}")
public String editJob(#PathVariable("jobId") Integer jobId,Model model){
model.addAttribute("id",jobId);
return "edit";
}
in which i am passing the jobId to get the instance of the job by id and returning "edit" string so that it maps to edit.jsp as per the InternalResourceViewResolver. But when i click on the link it goes to /edit/44 in which case 44 would be the id of the job for which the edit link belongs to. Finally i got the error stating no resource found.
home.jsp
<%# taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# page session="false"%>
<html>
<head>
<link rel="stylesheet" type="text/css"
href="<c:url value="/resources/css/style.css"/>" />
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<title>Home</title>
</head>
<body id="main">
<div class="container">
<h2 style="color:white">All posted jobs</h2>
<c:if test="${empty jobList}">
<h6>No Job Post Yet</h6>
</c:if>
<c:if test="${!empty jobList}">
<c:forEach items="${jobList}" var="job">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">${job.title }</h3>
</div>
<div class="panel-body">${job.description }</div>
<div class="panel-footer">
<a id="link" href="delete/${job.id }">Delete</a>
<a id="link" href="edit/${job.id}">Edit</a>
</div>
</div>
</c:forEach>
</c:if>
<section>
<form:form method="post" action="add" modelAttribute="job"
class="form-horizontal">
<div class="form-group" id="addForm">
<form:label class="control-label" path="title">Title:</form:label>
<form:input class="form-control" path="title"/>
<form:label class="control-label" path="description">Description</form:label>
<form:textarea class="form-control" rows="5" path="description" />
<button class="btn btn-success">
<span class="glyphicon glyphicon-plus-sign"></span> Add a Job
</button>
</div>
<a id="addJob" href="add">+</a>
</form:form>
</section>
</div>
JobController.java
package com.job.src;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.job.src.model.Job;
import com.job.src.services.JobService;
#Controller
public class JobController {
#Autowired
private JobService jobService;
#RequestMapping(value= "/")
public String listJobs(Map<String,Object> map){
map.put("job", new Job());
map.put("jobList", jobService.listJobs());
return "home";
}
#RequestMapping(value= "/add", method=RequestMethod.POST)
public String addJob(Job job){
jobService.addJob(job);
return "redirect:/";
}
#RequestMapping("/delete/{jobId}")
public String deleteJob(#PathVariable("jobId") Integer jobId){
jobService.removeJob(jobId);
return "redirect:/";
}
#RequestMapping("/edit/{jobId}")
public String editJob(#PathVariable("jobId") Integer jobId,Model model){
model.addAttribute("id",jobId);
return "edit";
}
}
edit.jsp
<%# taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css"
href="<c:url value="/resources/css/style.css"/>" />
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form:form method="post" action="editSuccess" modelAttribute="job"
class="form-horizontal">
<div class="form-group" id="addForm">
<form:label class="control-label" path="title">Title: </form:label>
<form:input class="form-control" path="title" />
<form:label class="control-label" path="description">Description</form:label>
<form:textarea class="form-control" rows="5" path="description" />
<button class="btn btn-success">
<span class="glyphicon glyphicon-plus-sign"></span> Add a Job
</button>
</div>
</form:form>
In editJob method your are returning only id of job with model attribute to edit.jsp. But actually on edit.jsp page you need job object so you need to get job object by id add it as model attribute.
#RequestMapping("/edit/{jobId}")
public String editJob(#PathVariable("jobId") Integer jobId,Model model){
//model.addAttribute("id",jobId); this is wrong
Job job = jobService.getJobById(jobId);
//write method in jobservice to get job by id i.e. getJobById(Integer jobId);
model.addAttribute("job",job)
return "edit";
}
Related
I am newbie in spring mvc. I am trying to make simple crud in spring using MySQL jdbc. For datamapping I have used spring form. Whenever I try to use spring form it shows an Error
Error is here
Whenever i remove spring form and use normal form it looks ok but shows an error when used spring form. The error says java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userData' available as request attribute
header.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">SpringCRUDDemo</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li>Home</li>
<li>View</li>
<li>Update</li>
<li>Delete</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
<li><span class="glyphicon glyphicon-log-in"></span> Login</li>
</ul>
</div>
</div>
</nav>
index.jsp
<%#include file="./shared/header.jsp" %>
<div class="container">
<form:form commandName="userData" action="#" method="post" enctype="multipart/form-data">
<label for="firstname" class="label">Enter your first name</label>
<form:input path="firstName"/>
</form:form>
</div>
servlet class
package com.nishan.springcruddemo.servlet;
import com.nishan.springcruddemo.daoimp.CustomerDaoImp;
import com.nishan.springcruddemo.entity.Customer;
import java.sql.SQLException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
*
* #author Dell
*/
#Controller
public class DefaultController {
#Autowired
CustomerDaoImp customerDaoImp;
#RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "index";
}
#RequestMapping(value = "/insert", method = RequestMethod.POST)
public String save(#ModelAttribute("userData") Customer customer) {
try {
customerDaoImp.insert(customer);
} catch (ClassNotFoundException | SQLException ex) {
System.out.println(ex.getMessage());
}
return "redirect:/index";
}
#RequestMapping(value = "/view", method = RequestMethod.GET)
public String viewCustomer() {
return "view-customer";
}
}
You have to Use #RequestParam to get single value.
To Bind form data with model class You need to create Model(POJO) as userData commandName="userData".CommandName and ModelClass Name both same.
Fields of class firstName and both same. Then Your Form Data Bind with Pojo It will come at your controller Class.
I hope it will help.
I want to add payments to my clients database but when I add the payments I got this error "GET NOT SUPPORTED" I don't know what's the problem. Can you guys help me?
#Controller
public class PaymentsController {
#Autowired
private UsersService usersService;
#Autowired
private PaymentsService paymentsService;
#RequestMapping(value = "/addPayments", method = RequestMethod.POST)
public String addPayments(HttpServletRequest request, ModelMap map) {
String user = request.getParameter("userId"); // this is the identifier for the user of this payment
String transactName = request.getParameter("transactName");
String paid = request.getParameter("paid");
String unpaid = request.getParameter("unpaid");
String balance = request.getParameter("balance");
String total = request.getParameter("total");
//.... get all other attributes you've passed from the form through request.getParameter("");
//next, check whether or not a user with the userId from the screen exists in the db
Users userObject = usersService.getUsers(user);
//.getUsersByUserId(user);
if (userObject != null) {
// this means that we have a valid user to insert the payment to
UsersPayments payment = new UsersPayments();
payment.setUsers(userObject);
payment.setTransactName(transactName);
payment.setPaid(paid);
payment.setUnpaid(unpaid);
payment.setBalance(balance);
payment.setTotal(total);
//.... set the other properties of UsersPayment object
paymentsService.addPayments(payment);
}
else {
// you have an error right here
}
map.put("paymentsList", paymentsService.getAllPayments());
return "payments";
}
}
payments.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# include file="/WEB-INF/jsp/includes.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="<c:url value="/resources/css/design.css" />" rel="stylesheet">
<link href="<c:url value="/resources/css/customized.css" />" rel="stylesheet">
<link href="<c:url value="/resources/css/bootstrap.css" />" rel="stylesheet">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Canadian Immigration Consultancy</title>
</head>
<body>
<div id="wrapper">
<div id="logo">
<img src="<c:url value="/resources/images/logo4.png" />" height="200px" width="230px"/>
<img src="<c:url value="/resources/images/header06.jpg" />" height="200px" width="765px"/>
</div>
<div class="red">
<div align="center" id="slatenav">
<ul>
<li>Home</li>
<li>View All</li>
<li>Reports</li>
<li>Add Leads</li>
<li><spring:message code="user.logout"/></li>
</ul>
</div>
</div>
<div id="balance" >
<form action="addPayments" method="POST">
<div class="well well-sm box16">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Payments</h3>
</div>
<div class="panel-body">
<div class="form-group">
<br><div class="col-sm-2 control-label">Transaction Name</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="transactName" autofocus />
</div>
</div>
<div class="form-group">
<br><div class="col-sm-2 control-label">Amount Paid</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="paid" />
</div>
</div>
<div class="form-group">
<br><div class="col-sm-2 control-label">Unpaid</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="unpaid" />
</div>
</div>
<div class="form-group">
<br><div class="col-sm-2 control-label">Total Balance</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="balance" />
</div>
</div>
<div class="form-group">
<br><div class="col-sm-2 control-label">Total Amount</div>
<div class="col-sm-10">
<input type="text" class="form-control" name="total" />
</div>
</div>
<div class="save">
<input type="submit" class="btn btn-success" value="Save" />
</div>
</form>
</div>
</div>
</div>
</body>
</html>
You only seem to have one handler mapping, and it's POST. Add another handler mapping for the same url path with GET. Consider the "POST Redirect GET" pattern as well.
Im using the below servlet to get the form values, when the form is posted im able to get the username and password but unable to access it in the mainpage.jsp which displays the username/password.
Servlet
package com.school.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import com.school.beans.Login;
#Controller
public class Logincontroller {
#RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView login() {
return new ModelAndView("login", "loginform", new Login());
}
#RequestMapping(value = "/validatelogin", method = RequestMethod.POST)
public String validatelogin(#ModelAttribute("SchoolManagement")Login login,
ModelMap model) {
model.addAttribute("username", login.getUsername());
model.addAttribute("password", login.getPassword());
System.out.println("useranme = " + login.getUsername());
System.out.println("password = " + login.getPassword());
return "mainpage";
}
}
login.jsp
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<!--
<script src="javascript/login.js"></script>
<link rel="stylesheet" type="text/css" href="css/login.css"/>
http://www.mkyong.com/spring-mvc/spring-mvc-how-to-include-js-or-css-files-in-a-jsp-page/
-->
<!--<script src="<c:url value="/resources/js/jquery.1.10.2.min.js" />"></script>-->
<link href="<c:url value="/resources/css/login.css" />" rel="stylesheet">
<script src="<c:url value="/resources/js/login.js" />"></script>
<script
src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<div id="top"></div>
<div id="middle">
<form:form method="POST" id="loginform" commandName="loginform"
action="/SchoolManagement/validatelogin">
<form:label path="username"> Username:</form:label>
<form:input path="username" /> <br>
<form:label path="password"> Password:</form:label>
<form:input path="password" />
<input type="submit" value="submit">
</form:form>
</div>
<div id="bottom"></div>
</body>
</html>
mainpage.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<!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=ISO-8859-1">
<title>MainPage</title>
</head>
<body>
<h2>Submitted Student Information</h2>
<table>
<tr>
<td>Name</td>
<td>${username}</td>
</tr>
<tr>
<td>Password</td>
<td>${password}</td>
</tr>
</table>
</body>
</html>
Try getting the values directly out of the request.
<%
String username = (String) request.getAttribute("username");
String password = (String) request.getAttribute("password");
%>
<table>
<tr>
<td>Name</td>
<td><%= username %></td>
</tr>
<tr>
<td>Password</td>
<td><%= password %></td>
</tr>
</table>
That should definitely work... if not, something's wrong with the setup.
your command name
commandName="loginform"
is different than model attribute
#ModelAttribute("SchoolManagement")
try to use same names
In my web application, I have a home page where the options available to the user are placed in a fixed sidebar in the top of the screen, and each one of this options are opened inside of a tag <div> in this same page.
My problem is: when this content is a form, and I submit it to the server, after the processing, the output page isn't opened in this <div>, but in the entire navigation space. What I want is a way of capture this return and display it in the same <div> it was originated.
the code for my home page is:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
<title>HorarioLivre</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="navbar-fixed-top.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy this line! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body onload="close_page()">
<!-- Fixed navbar -->
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">HorarioLivre</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>Evento</li>
<li>Lista Horarios</li>
<li>Cadastra Horarios</li>
<li>Usuarios</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
${usuario.nome} <b class="caret"></b>
<ul class="dropdown-menu">
<li>Perfil</li>
<li>Configurações</li>
<li>Sair</li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container">
<div class="page-header">
<h1></h1>
</div>
<div class="panel panel-default" id="results">
<div class="panel-heading">
<div align="right"><button type="button" class="btn btn-lg btn-danger" onclick="close_page()">Fechar</button></div>
</div>
<div class="panel-body" id="content">
Panel content
</div>
</div>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script>
function load_page(url){
$('#results').css("display", "block");
$('#content').load(url);
$('#container').draggable();
}
function close_page(){
$('#results').css("display", "none");
$('#content').empty();
}
</script>
</body>
</html>
I am using Spring, and the pages linked here are handled by Controller. By example,the page "cadastra_evento.html" is:
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!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>Lista de Eventos</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="alert alert-info">
<strong>Eventos</strong> Segue a lista de eventos cadastrados.
</div>
<div class="container">
<div class="row">
<div class="col-md-3">Nome</div>
<div class="col-md-3">Descrição</div>
<div class="col-md-3">Periodo</div>
<div class="col-md-3">Duração</div>
</div>
<c:forEach var="item" items="${lista}">
<div class="row">
<div class="col-md-3"><c:out value="${item.nome}"/></div>
<div class="col-md-3"><c:out value="${item.descricao}"/></div>
<div class="col-md-3"><c:out value="${item.data_inicial}"/> - <c:out value="${item.data_final}"/></div>
<div class="col-md-3"><c:out value="${item.duracao}"/></div>
</div>
</c:forEach>
</div>
<div class="alert alert-info">
<strong>Novo</strong> Cadastre um novo evento.
</div>
<form method="post" action="cad_evento.html">
<input type="text" name="nome" placeholder="Nome" size=20 maxlength=40> <br/>
<input type="text" name="descricao" placeholder="Descrição" size=30 maxlength=100> <br/>
<h3>Periodo da Data</h3>
inicio: <input name="data_inicial" placeholder="DD-MM-AAAA" required pattern="\d{2}-\d{2}-\d{4}" /> <br/>
final: <input name="data_final" placeholder="DD-MM-AAAA" required pattern="\d{2}-\d{2}-\d{4}" /> <br/>
<h3>Periodo do Horário</h3>
inicio: <input name="hora_inicial" placeholder="HH:MM:SS" required pattern="\d{2}:\d{2}:\d{2}" /> <br/>
final: <input name="hora_final" placeholder="HH:MM:SS" required pattern="\d{2}:\d{2}:\d{2}" /> <br/>
<input type="text" name="duracao" placeholder="duração" size=20 maxlength=2> <br/>
<button type="submit" class="btn btn-lg btn-primary">Cadastrar</button>
</form>
</body>
</html>
To finish, the page "cad_evento.html" used as action for the form above, is handled by method of same name from Controller:
#RequestMapping(value="/cad_evento", method=RequestMethod.POST)
public ModelAndView cadastra_evento(#RequestParam("nome") String nome, #RequestParam("descricao") String descricao, #RequestParam("data_inicial") String data_inicial, #RequestParam("hora_inicial") String hora_inicial, #RequestParam("data_final") String data_final, #RequestParam("hora_final") String hora_final, #RequestParam("duracao") int duracao) {
if(sessao != null)
{
if(sessao.getUsuario().temAutorizacao("cad_evento"))
{
Date d_inicio = new Date(Date.parse(data_inicial));
Date d_final = new Date(Date.parse(data_final));
Time h_inicio = new Time(Time.parse(hora_inicial));
Time h_final = new Time(Time.parse(hora_final));
EventoDAO evento = new EventoDAO(nome, descricao, d_inicio, d_final, h_inicio, h_final, duracao, sessao.getUsuario());
int saida = evento.cadastra();
if(saida == 0)
{
ModelAndView mav = new ModelAndView();
mav.addObject("message", "Erro ao cadastrar o evento");
return mav;
}
else
{
ModelAndView mav = new ModelAndView();
mav.setViewName("/listagem_evento");
return mav;
}
}
else
{
ModelAndView mav = new ModelAndView();
mav.addObject("message", "Usuário sem permissão de acesso");
return mav;
}
}
else
{
ModelAndView mav = new ModelAndView();
mav.setViewName("/usuario_login_page");
return mav;
}
}
Someone have any thoughts about how to do that?
Well, spring mvc just open new page with a content you set in ModelAndView. If you want to load somthing just in some part of page ( in this case ) there pure javascript / jquery ajax is needed. So steps needed here:
Add javascript which will do ajax request to controller
Controller need to return JSON ( #ResponseBody can help you )
You have to do some DOM manipulation using javascript/jquery to put JSON answer to your div.
I need to take the value of the select option to send it to another page to be processed, but can not capture the value.
any ideas?
the select is loaded from the database, that part works, shows the categories of product.
<%#page import="com.sun.xml.internal.txw2.Document"%>
<%#page import="java.util.ArrayList"%>
<%# page import = "com.seminario.beans.categoria" %>
<%# page import = "com.seminario.datos.DbCategoria" %>
<%# page import = "com.seminario.beans.Producto" %>
<%# page import = "com.seminario.datos.DbProducto" %>
<jsp:useBean id="dataProd" class="com.seminario.datos.DbProducto" scope="page"/>
<jsp:setProperty name="dataProd" property="*"/>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link href="../stylo.css" rel="stylesheet" type="text/css" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Alta Producto</title>
</head>
<%
categoria c = new categoria();
DbCategoria bdc = new DbCategoria();
ArrayList <categoria> myList = new ArrayList();
myList = bdc.SelectAll();
%>
<body>
<h1>Nuevo Producto</h1>
<form name ='formulario' action='nuevoProducto.jsp' method='post' >
Descripcion<input name='descripcion' type='text' size='20' required><br>
Precio<input name='precio' type='text' size='20' required><br>
Stock<input name='stock' type='text' size='20' required><br>
**Categoria <select name="categoid" id="categoid">
<% for(int i=0;i<myList.size();i++){%>
<option value="<%= myList.get(i).getId() %>" > <%out.print(myList.get(i).getDescripcion());%></option>
<%}%>
</select><br>**
Imagen<input name="imagen" text="seleccionar archivo" type="file" size="10" accept="image/jpg" /><br>
<input type ="submit" value ='Guardar' />
<!-- <input type="submit" value="guardar">-->
</form>
<br><br><a href='menuAdmin.jsp'>Volver al menu principal</a>
</body>
</html>