| | |
String compare with Form field
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2009
Posts: 2
Reputation:
Solved Threads: 0
I am new to JSP and am having trouble comparing string with the value in a form field submitted.
The following is the code that I am executing through Tomcat and is not giving me the desired result:
You will notice that even though the correct string "compareme" is submitted in the form, the string comparison still fails. I have tried appending .toString() and .trim() to myvar but that has not helped either.
I am obviously missing something very basic in JSP. Please help.
The following is the code that I am executing through Tomcat and is not giving me the desired result:
java Syntax (Toggle Plain Text)
<% String myvar = request.getParameter("var1"); boolean first = false; if (myvar == null) { first = true; } else { if (myvar == "compareme") out.println("string matches"); else out.println("string MISMATCH"); } %> <html> <head><title>String compare with Form Input</title></head> <body> <h2>If you enter input as "compareme", I should say "MATCH", else "MISMATCH"</h2> <% if (! first) { %> Input was <%= myvar %> <br> <% } %> <hr> <form>Please enter a string <input name=var1> and <input type=submit></form> </body> </html>
I am obviously missing something very basic in JSP. Please help.
You are missing something basic in Java which is why you should leave JSP and practice more:
JSP Syntax (Toggle Plain Text)
if (myvar.equals("compareme")) out.println("string matches"); else out.println("string MISMATCH");
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- how to retrive muliple database values and compare with jsp field vlaues (Java)
- Not getting information from the database (PHP)
- Fatal error: require once (PHP)
- comparing elemets of arraylist (Java)
- error C2059: syntax error : 'namespace' (C++)
- Searching a Text Field in a JList (Java)
- Please help me :"login form use drag and drop toolbox" ! (C#)
- Compilation Error Handles cmdLogin.ServerClick (ASP.NET)
Other Threads in the JSP Forum
- Previous Thread: Pass input field to hyperlink parameter
- Next Thread: Servlet and JSP
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web






