jsp - Request.getParameter() method not working -
i creating website , having trouble in retrieving value textbox. having login page in user inputs username. have take value textbox , send login.jsp
request.getparameter()
method takes value of textbox. guess request.getparameter()
not working.please me in pointing mistake. here code
<!doctype html> <html> <head> <title></title> <meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="login.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <style> .center{ margin: auto; width: 400px; height: 400px; border: 3px; padding-top: 50px; } </style> </head> <body> <div class="center" > <form action="login.jsp" method="post"> <div> <img src="images/crms.png" style="padding-bottom:50px;" width="440" height="240"> </div> <div id="comment_bubble" > <div class="form" id="form1"> <h2 style="padding-left:125px;">sign in</h2> <img src="images/hooo.png" style="padding-left:120px;padding-bottom:10px; "> <div class="form-group has-feedback"> <input type="text" class="form-control" id="email" placeholder="username" name="inputtext" value=""><span class="glyphicon glyphicon-user form-control-feedback " id="username"></span><br></div> <div class="form-group has-feedback"> <input type="password" class="form-control" id="password" placeholder=" password" align="center" name="pwd" value=""><span class="glyphicon glyphicon-lock form-control-feedback" id="pass"></span><br></div> <button id="button" type="button" class="btn btn-default" value="submit" onclick="callfun();" >submit</button><br><br> <a href="#mymodal" data-toggle="modal" id="register">create new account</a> </div> </div> </form> <div class="modal fade" id="mymodal" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">x</button> <h3>create new account</h3> </div> <div class="modal-body"> <div class="form-group" id="form2"> <label for="sel1"> designation</label> <select class="form-control" id="sel1" > <option>director</option> <option>faculty</option> <option>technician</option> </select><br> <input type="email" class="form-control" placeholder="username"><br> <input type="email" class="form-control" placeholder="faculty_id"><br> <input type="password" class="form-control" placeholder="password"><br> <input type="password" class="form-control" placeholder="re-type password"><br> <button id="button2" type="button" class="btn btn-primary" >submit</button> </div> </div> </div> </div> </div> </div> <script> function callfun() { location.href = "login.jsp"; } </script> </body> </html>
and here jsp code:
<%@page import="java.sql.resultset"%> <%@page import="java.sql.statement"%> <%@page import="java.sql.drivermanager"%> <%@page import="java.io.*,java.util.*"%> <%@page import="java.sql.connection"%> <% string userid = request.getparameter("inputtext"); if(userid==null){ out.println("userid missing"); } else{ string pass = request.getparameter("pwd"); class.forname("com.mysql.jdbc.driver"); connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/crms", "root", "root"); statement st = con.createstatement(); resultset rs = st.executequery("select * login username='" + userid + "'"); if (rs.next()) { if (rs.getstring(2).equals(pass)) { string site=new string("complain.jsp"); response.setstatus(response.sc_moved_temporarily); response.setheader("location",site); } else { out.println("else running"); } } } %>
your password input field password have name , can password value name. example
<input type="password" value="" name="pass">
your can value form backend calling
string pass = request.getparameter("pass");
anyways parameter value, should submit (post) form specific url. can include id form
<form action="login.jsp" method="post" id="myform">
and script should
<script> function callfun() { $("#myform").submit(); } </script>
and let me know, if works. thanks.
Comments
Post a Comment