• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Embed form element value in scriplet?

 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please refer follwoing script. What I am trying here is to build up an update based on textfield newpassword in the form. Seems the update statmt does not get constructed right. Seems many examples where we embed scriplets in form elements. Here I am creating a scriplet that refers a form element value. How I can I do that?

<%
String msg = "";
String query = "";


// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
String URL= application.getInitParameter("url_path");
String user=application.getInitParameter("userid");
String pass=application.getInitParameter("passwd");
Connection conn = null;
String newpassword=request.getParameter("NewPassword");
conn = DriverManager.getConnection (URL, user, pass);
Statement stmt = conn.createStatement();

//Build the upadte string here

updatestmt = "update users set user_pass '" + %>+ document.ChangePassword.NewPassword.value + <%"' where user_name = 'tom' ";

stmt.executeUpdate(query);

%>
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what you seem to by trying to do is include javaScript, which runs on the client, inside a java Scriptlet, which runs on the server. No way is this going to work!

The process you have to follow is:
  • create a jsp or even just a plain html document with a <form> tag and an action attribute pointing to the jsp containing your JDBC logic.
  • The JSP with the <form> tag must also have a password field and a submit button. The Jsp with the JDBC logic will be called when the user presses the submit button.
  • Somewhere in your second JSP (The one with the JDBC logic) you should put the statement: "String newPassword = request.getParameter("NewPassword");" This statement retrieves the value passed on by the previous form.
  • use the variable newPassword when building your SQL statement.


  • If you want, both the form JSP and the JDBC jsp can be the same document, but you will have to include logic to determine what state you are in. Am I in the state where the user first brings up the page? or am I in the state where the user has already submitted the page and needs a confirmation that the change worked? Hint: If request.getParameter("NewPassword") returns null, you are in the first state.

    I hope this helps.
    reply
      Bookmark Topic Watch Topic
    • New Topic