validation for jsptextarea in bean class

I want write code for validation on server side in java
In jsp i have textarea in that i want enter the comments

Validation is --When number of characters are less than or equals to 3000

I am working in atg application server and atg dynamoframework i developed jsp and bean for properties. in jsp i have button,when i click the button it check the validation and submit the button it show the error message or alert message

Thanks
Srinivasrao
srinivasraodumpalaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

radarshCommented:
I'm not clear whether you want server side or client side validation.
I'm also not clear on whether number of characters greater than 3000 is a failure
or a success condition. I'll assume failure here.

Anyways, I'll give both of them.


<head>
<script type="text/javascript">
    function validateText()
    {
        var text = document.MyForm.Text.value;
        if(text.length > 3000)
        {
            alert('Text entered too long');
        }
    }
</script>
</head>

....
....

<form name="MyForm">
....
....
<textarea name="Text" rows="20" cols="60"></textarea>
<input type="button" value="Submit" onclick="javascript:validateText();">

</form>


Now, server side validation.


I don't know what you are using for Server Side coding. Servlets? Struts? what?
If it is servlets, you can do

String text = request.getParameter("Text");
if(text.length() > 3000)
{
    request.setAttribute("error", "Text too long");
}

// then forward to the same JSP you came from.

In your JSP, put something like this:

<%
    if(request.getAttribute("error") != null)
    {
%>
<b><font color="red"><%=request.getAttribute("error")%></font></b>
<%
    }
%>


________
radarsh
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.