I have one page in jsp which has one textbox and submit button. when i enter value in textbox and click on submit it is redirecting me to new page. But issue is i want to validate that textbox should not have any blank space at the start and end of value entered in text box. Below is the code which i am trying
<%
String Hostname=user2.getHost();
String Wrong=" "+Hostname+" ";
if (Hostname != null)
{
if (Hostname == " "+Hostname+" ")
{
%>
<div class="alert-box" > <span>Warning: </span>Not a valid hostname !! <% out.println("Hostname ='"+Hostname+"'"); %></div>
<%
}
else
{
pageContext.forward("InstanceList.jsp");
}
}
else
{
pageContext.include("NoHost.jsp");
}
%>
I am trying below if statement. If found hostname with blank space at start or end it should give alert message but every time it is going in first else and running InstanceList.jsp
if (Hostname == " "+Hostname+" ")
whereas first check of hostname null is working properly.
Please help if i am doing something wrong.