Hello!
I have a small problem with my JSP-code, im "playing" to learn abit so the program dont really do much but still... I want to get a regex to check the input in my form, but dont know how i can do that when im using beans in JSP.
Here is my first codepart (index.jsp)
Here is the page i send the form to and where the bean gets the form and sends it to my Java-class (next codepart)Code:<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Submit!</title> <link type="text/css" href="Style.css" rel="stylesheet"/> </head> <body> <logo><img src="logo.jpg" width="459" height="152" alt="logo"/></logo> <div1> <form method=POST action="submit.jsp"> <label>Item:</label> <input type="text" name="item" size="20"<BR> <label>Price:</label> <input type="text" name="price" size="20"<BR> <label>Stock:</label> <input type="text" name="stock" size="20"<BR> <input type="submit" value="Lägg in item"> </form> </div1> </body> </html>
Here is my Javaclass...Code:<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import="java.io.*" %> <%@ page import="java.util.*" %> <%@page import="item.Items" %> <jsp:useBean id="item" scope="page" class="item.Items" /> <jsp:setProperty name="item" property="*" /> <% if(session.getAttribute("Array") == null) { ArrayList<Items> arr = new ArrayList<Items>(); arr.add(item); session.setAttribute("Array", arr); } else { ArrayList<Items> ar2 = (ArrayList<Items>) session.getAttribute("Array"); ar2.add(item); session.removeAttribute("Array"); session.setAttribute("Array", ar2); } response.sendRedirect("view.jsp"); %>
Now to my question, where and how do i put my Regex so the user can get a errormsg in index if he types anything wrong? And lets him correct it. I would love an example in my own code so i know how to do.Code:public class Items { private String item; private int price, stock; public int getStock() { return stock; } public void setStock(int stock) { this.stock = stock; } public void setItem( String value ) { item = value; } public void setPrice( int value ) { price = value; } public String getItem(){ return item; } public int getPrice(){ return price; } }
/Nick3


LinkBack URL
About LinkBacks




Reply With Quote



Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum