简体   繁体   中英

How do I store null value from input field when the input field is not necessarily required in JSP?

JSP

email = request.getParameter("vemail");
String sql = "insert into regdriver(email)values ('"+email+"')";    
st=con.createStatement();
rs=st.executeQuery(sql);

HTML Tag

<input type="email" name="vemail" id="mail" placeholder="">

If I did not enter any value in email field the null value is stored in database. Apart from null value, I want nothing to be stored in database.

Not quite sure about the OP's point, if you just don't want to modify database when the email is null, just add if statement as below.

email = request.getParameter("vemail");
if(email != null){
    String sql = "insert into regdriver(email)values ('"+email+"')";    
    st=con.createStatement();
    rs=st.executeQuery(sql);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM