+ Reply to Thread
Results 1 to 4 of 4

Thread: Regex in JSP with beans!

  1. #1
    Newbie nick3 is an unknown quantity at this point
    Join Date
    Feb 2009
    Posts
    24

    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. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,668
    Blog Entries
    57

    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.
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  3. #3
    Newbie nick3 is an unknown quantity at this point
    Join Date
    Feb 2009
    Posts
    24

    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?

  4. #4
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,668
    Blog Entries
    57

    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.
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Regex Expressions
    By John_L in forum Perl
    Replies: 13
    Last Post: 02-14-2009, 01:01 PM
  2. Replies: 0
    Last Post: 08-18-2008, 08:17 AM
  3. Replies: 0
    Last Post: 10-19-2007, 11:57 AM
  4. Tutorial: C# Regex
    By NeedHelp in forum CSharp Tutorials
    Replies: 2
    Last Post: 05-01-2007, 06:44 AM
  5. regex (yuck)
    By John in forum PHP Forum
    Replies: 9
    Last Post: 08-09-2006, 12:35 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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