Closed Thread
Results 1 to 4 of 4

Thread: Regex in JSP with beans!

  1. #1
    nick3 is offline Newbie
    Join Date
    Feb 2009
    Posts
    29
    Rep Power
    0

    Regex in JSP with beans!

    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)

    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 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"%>
    <%@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");    
    %>
    Here is my Javaclass...

    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;
        }
    
    }
    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.

    /Nick3

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,475
    Blog Entries
    75
    Rep Power
    143

    Re: Regex in JSP with beans!

    You would need to do that with JavaScript that is triggered when the user tries to submit the form.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    nick3 is offline Newbie
    Join Date
    Feb 2009
    Posts
    29
    Rep Power
    0

    Re: Regex in JSP with beans!

    Hmm ok, i dont know any javascript really, if its not to complicated, like to show me how to do it?

  5. #4
    Join Date
    Jul 2006
    Posts
    16,475
    Blog Entries
    75
    Rep Power
    143

    Re: Regex in JSP with beans!

    I would recommend reading up on javascript at W3Schools Online Web Tutorials . There is a LOT you can do with it, and the details of what you want will affect the code you use.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Need some help with Regex
    By Edvinas in forum C# Programming
    Replies: 3
    Last Post: 06-25-2010, 12:12 PM
  2. Replies: 0
    Last Post: 10-19-2007, 09:57 AM
  3. Net Beans..You need to see this.
    By techni68 in forum Software Development Tools
    Replies: 2
    Last Post: 01-20-2007, 09:45 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts