mysql - Program will not read my if statement -


i doing project , done. took me while code run got it. assignment make html form, connect mysql using jsp, , insert values database or delete values database. password protected. said have gotten compile without error if statement have implemented not being picked up. wondering if me figure why happening. im going paste html code jsp.

html code

<?xml version = "1.0" encoding = "utf-8"?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd">  <html xmlns = "http://www.w3.org/1999/xhtml"> <head> <title> assignment 3 </title> </head> <body> <h3> song name form </h3> <form action = "hgooding.jsp" method = "post">      <table border = "1">         <tr>             <td>song title: </td>             <td> <input type = "text" name = "song"/> </td>         </tr>         <tr>             <td>artist </td>             <td> <input type = "text" name = "artist"/> </td>         </tr>         <tr>             <td>password: </td>                         <td> <input type = "password" name = "pass1"                 size = "20"/> </td>         </tr>         </table>         <br>           <input type = "radio" name = "option" value = "add"/> add            <input type = "radio" name = "option" value = "delete"/> delete                 <br>                             <input type = "submit" value = "submit" />  </form> </body> </html> 

jsp code

<%@ page import = "java.sql.*" %>  <html> <head> <title> database jsp </title></head> <body> <%  string connectionurl = "jdbc:mysql://sql.njit.edu:3306/hg33";     connection connection = null;     statement stm = null;     resultset rst=null;  class.forname("com.mysql.jdbc.driver").newinstance();      connection = drivermanager.getconnection(connectionurl, "hg33", "grapes34");      string song = request.getparameter("song");      string artist = request.getparameter("artist");      string action = request.getparameter("option");      string pass2 = request.getparameter("pass1");      statement stminsert = null;      stminsert = connection.createstatement(); if (pass2 == "apples4")    {           if (request.getparameter("action").equals("add"))     {       string sqlupdate1=("insert songs values('"+song+"', '"+artist+"')");     stm.executeupdate(sqlupdate1);         out.println("hi!"); } if (request.getparameter("action").equals("delete"))  {     string sqlupdate2=("delete music song =('"+song+"')");     stm.executeupdate(sqlupdate2); }         rst = stm.executequery("select * music");    } else    {     out.println( "password not correct!!!" );    }              out.println("insert attempted"); %> </body> </html> 

i guess ur condition in if statement should this

if (action.equals("add")){.........................} 

or

if (action == "add"){.........................} 

instead of

if (request.getparameter("action").equals("add")){....................}  

coz u catch option in action variable this

string action = request.getparameter("option")  

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -