943,696 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Marked Solved
  • Views: 79146
  • JSP RSS
Aug 26th, 2005
0

JSTL compare string

Expand Post »
hi, :p

i am trying to achieve a registration page in JSP. i am using tag library to do this.

c tag library and Sql tag library.

JSP Syntax (Toggle Plain Text)
  1.  
  2.  
  3.  
  4.  
  5.  
  6. <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
  7. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  8.  
  9. <c:if test="${param.submitted}">
  10. <c:if test="${empty param.name}" var="noname" />
  11. <c:if test="${empty param.pw}" var="nopw" />
  12. <c:if test="${empty param.cpw}" var="nocpw" />
  13. <c:if
  14. test="${not (noname or nopw or nocpw or requestScope.takenName)}">
  15.  
  16.  
  17. <c:set value="${param.name}" var="name" scope="request" />
  18. <c:set value="${param.pw}" var="pw" scope="request" />
  19. <c:set value="${param.cpw}" var="cpw" scope="request" />
  20.  
  21.  
  22.  
  23.  
  24. <jsp:forward page="postregister.jsp"/>
  25.  
  26.  
  27.  
  28. </c:if>
  29. </c:if>
  30.  
  31. <html>
  32. <head>
  33. </head>
  34. <body bgcolor="CFECEC" >
  35.  
  36.  
  37.  
  38. <form method="post" name="frmRegister">
  39. <input type="hidden" name="submitted" value="true"/>
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. <script type="text/javascript">
  47.  
  48. <!--
  49.  
  50. function add_onclick() {
  51.  
  52. var TRUE = new Boolean("True")
  53. var FALSE = new Boolean("False")
  54.  
  55. blnError = FALSE
  56. strError = "The following problems were found in your registration form: \n\n"
  57.  
  58.  
  59.  
  60. if (frmRegister.name.value == "")
  61. {
  62. blnError = TRUE
  63. strError = strError + " - You must provide a Login Name\n"
  64. };
  65.  
  66. if (frmRegister.pw.value == "")
  67. {
  68. blnError = TRUE
  69. strError = strError + " - You must provide a Password\n"
  70. };
  71. if (frmRegister.cpw.value == "")
  72. {
  73. blnError = TRUE
  74. strError = strError + " - You must confirm your Password\n"
  75. };
  76.  
  77.  
  78. if (frmRegister.pw.value != frmRegister.cpw.value)
  79. {
  80. blnError = TRUE
  81. strError = strError + " - Your Password does not match\n"
  82. };
  83.  
  84. if (blnError == TRUE)
  85. {
  86. strError = strError + "\nPlease correct these mistakes and try again."
  87. alert(strError)
  88. }
  89. else
  90. {
  91. frmRegister.submit()
  92. };
  93.  
  94. }
  95.  
  96. //-->
  97. </SCRIPT>
  98.  
  99.  
  100.  
  101.  
  102. <p align="left"><b> Register <hr> </p>
  103. <p align="center"><b>Please complete the following registration form</b> <hr><br><br>
  104.  
  105.  
  106.  
  107. <img src="dmu.jpg" alt="DMU University" align="left">
  108. <img src="dmu.jpg" alt="DMU University" align="right">
  109.  
  110.  
  111.  
  112. <table BORDER="0" ALIGN="CENTER" VALIGN="TOP" CELLPADDING=2 CELLSPACING=0>
  113. <tr>
  114. <td><Strong>Username</strong></td>
  115. <td><input type="text" name="name" value="<c:out value="${param.name}" />"
  116. />
  117.  
  118. </td>
  119. </tr>
  120.  
  121.  
  122. <tr>
  123. <td><Strong>Password</strong></td>
  124. <td> <input type="password" name="pw" value="<c:out value="${param.pw}"/>"
  125. />
  126.  
  127.  
  128.  
  129.  
  130. <tr>
  131. <td><Strong>Confirm password</strong></td>
  132. <td> <input type="password" name="cpw" value="<c:out value="${param.cpw}"/>"
  133. />
  134.  
  135. <tr><td>&nbsp;</td>
  136. <td><input type="submit" value="register"LANGUAGE=javascript onclick="return add_onclick()" />
  137. </td>
  138. </tr>
  139.  
  140.  
  141.  
  142.  
  143.  
  144. </table>
  145. <img src="dmu.jpg" alt="DMU University" align="left">
  146. <img src="dmu.jpg" alt="DMU University" align="right">
  147.  
  148.  
  149.  
  150. </form>
  151. </body>
  152. </html>

code describe dabove is register.jsp which send info to postregister.jsp. which described below
JSP Syntax (Toggle Plain Text)
  1. <%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
  3.  
  4.  
  5.  
  6.  
  7. <c:choose>
  8.  
  9. <c:when test ="${param.pw == param.cpw}">
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. <sql:setDataSource
  17. dataSource= "jdbc/ma123"
  18. scope="session"/>
  19.  
  20.  
  21.  
  22.  
  23. <sql:transaction isolation="serializable">
  24. <sql:query var="result" >
  25. select username from rptable where username=?
  26. <sql:param value="${requestScope.name}" />
  27.  
  28.  
  29.  
  30.  
  31. </sql:query>
  32.  
  33.  
  34.  
  35. <sql:update>
  36. insert into rptable(username,password) VALUES (?,?);
  37. <sql:param value="${requestScope.name}" />
  38. <sql:param value="${requestScope.pw}" />
  39.  
  40. </sql:update>
  41.  
  42. </sql:transaction>
  43.  
  44. </c:when>
  45. <c:otherwise>
  46. <c:redirect url="register.jsp" >
  47. </c:redirect>
  48. </c:otherwise>
  49. </c:choose>
  50. <%----
  51. <c:set var="user" scope="session" value="${requestScope.name}" />
  52. ---%>
  53. <jsp:forward page="login.jsp"/>
  54.  
  55.  
  56.  
  57.  
  58.  
  59. <%----
  60.  
  61. it trasfering same data 2 times in database.
  62.  
  63. ---%>

it is transfering same data 2 times. so i do not understand what to do to compare password and confirm password.

any help would be greateful!!!!!!
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
hellofriend is offline Offline
1 posts
since Aug 2005
Aug 27th, 2008
0

Re: JSTL compare string

try put after onClick parans in input submit the value return false; <input onClick="test(); return false"/>
Reputation Points: 10
Solved Threads: 1
Newbie Poster
fbeli is offline Offline
1 posts
since Aug 2008
Aug 27th, 2008
-1

Re: JSTL compare string

Awn, I think he may already sorted or give up on this problem. Post is 3 year OLD!!!!!!!!
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004
Sep 9th, 2008
0

Re: JSTL compare string

lol,so old post .........




<URL SNIPPED>
Last edited by peter_budo; Sep 9th, 2008 at 4:46 am. Reason: Keep It Spam-Free - Do not spam, advertise, plug your website, or engage in any other type of self promotion.
Reputation Points: 6
Solved Threads: 1
Newbie Poster
haoyou2008 is offline Offline
7 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: retrieve request parameter of 1 frame to another
Next Thread in JSP Forum Timeline: JSP: Problem with Integer Values, not assigning type correctly





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC