Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

Jsp Validating Form

jsp validation

  • Please log in to reply
No replies to this topic

#1 mctim


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 110 posts

Posted 29 June 2012 - 09:14 AM

Here's some code I have:
if (asinInput.value == "") {
    alert('You must enter an Asin.');   
    return false;
   else {
    DumperHelper dHelper = DumperHelper.getDumperHelper("MyCompany");
    String asinInput = request.getParameter(ProductKeyReportServlet.ASIN_INPUT_FIELD);
    String[] lines = asinInput.split("\n");
    for(int i = 0; i < lines.length; i++) {
	    String[] lines2 = lines[i].split("\r");
	    for(int j = 0; j < lines2.length; j++) {
		    String[] asins = lines2[i].split(",");
		    for(int k = 0; k < asins.length; k++){
			    if(!dHelper.doesAsinExist(asins[i].trim(), "1")) {
				    %>alert('One or more of the asins entered are not valid');
				    return false <%

What you see there is a some jsp code in the body of a javascript else satement. What I'm trying to do is get the the user entered text and parse it to see if the input is valid. Two questions: Can I do this? I've come to understand that the jsp code is the first to get rendered so if that is true it sounds like I cant. Secondly, What is the proper way to get javascript variables and set them to strings in jsp.
  • 0

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download