6 Replies - 196 Views - Last Post: 24 April 2019 - 04:15 AM

#1 luliligavu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 26-March 19

How to prevent and remove whitespace or newlines in jsp response

Posted 22 April 2019 - 03:41 AM

My jsp page send " okay" or " not" including whitespace. How to prevent and remove whitespace or newlines in jsp response

valid.js


window.onload=initPage;
function initPage(){
    alert("Browser Started");
    //call checkUsername function
     document.getElementById("username").onblur=checkUsername;
 }
function checkUsername(){
    request=createRequest();
    if(request==null){
        alert("Unable to create request");
    }else{
        alert("Request Object Created")
         var theName = document.getElementById("username").value;
         var username = escape(theName);
         //create url pass username
         var url= "checkName.jsp?username=" + username;
         //any change execute showUsernameStatus function
         request.onreadystatechange = showUsernameStatus;
         request.open("GET", url, true);
         request.send(null);
    }
}
function showUsernameStatus(){
    if (request.readyState == 4) {
        if (request.status == 200) {
            var val=request.responseText;
            alert("Response: "+val);
             if (val == "okay") {
                    //something
                  } else {
                    //something
                  }
        }
    }
}


checkName.jsp

<%@ page language="java"
    pageEncoding="UTF-8"%>
<%String username=request.getParameter("username");
    System.out.println("Username:"+username);
    if(!username.equals("") && username!=null){
        if(!username.equals("Raju")){
            out.print("okay");
            System.out.println("okay");
        }else{
            out.println("not");
            System.out.println("not");
        }
    }
%>


Is This A Good Question/Topic? 0
  • +

Replies To: How to prevent and remove whitespace or newlines in jsp response

#2 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2853
  • View blog
  • Posts: 11,185
  • Joined: 03-December 12

Re: How to prevent and remove whitespace or newlines in jsp response

Posted 22 April 2019 - 05:05 AM

trim()
Was This Post Helpful? 1
  • +
  • -

#3 luliligavu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 26-March 19

Re: How to prevent and remove whitespace or newlines in jsp response

Posted 22 April 2019 - 06:21 AM

without using any methods can we do that?

This post has been edited by luliligavu: 22 April 2019 - 06:22 AM

Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 2853
  • View blog
  • Posts: 11,185
  • Joined: 03-December 12

Re: How to prevent and remove whitespace or newlines in jsp response

Posted 22 April 2019 - 06:32 AM

What do you mean, without methods?
Was This Post Helpful? 0
  • +
  • -

#5 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 224
  • View blog
  • Posts: 1,260
  • Joined: 05-December 13

Re: How to prevent and remove whitespace or newlines in jsp response

Posted 22 April 2019 - 09:41 AM

They're all coming out of the woodwork today Andrew :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#6 luliligavu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 26-March 19

Re: How to prevent and remove whitespace or newlines in jsp response

Posted 23 April 2019 - 03:42 AM

View Postastonecipher, on 22 April 2019 - 06:32 AM, said:

What do you mean, without methods?

how they(white spaces or newlines) occurs in jsp page and how to eliminate them in jsp

This post has been edited by luliligavu: 23 April 2019 - 03:42 AM

Was This Post Helpful? 0
  • +
  • -

#7 luliligavu   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 28
  • Joined: 26-March 19

Re: How to prevent and remove whitespace or newlines in jsp response

Posted 24 April 2019 - 04:15 AM

I got the answer

<%@ page trimDirectiveWhitespaces="true" %>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1