0

I am sending text values from jsp to servlet but in servlet request.getParameter() gives me null values. Below I am mentioning my JSP, Servlet and web.xml

REGISTER.JSP <form id="contactform" action="servlet/SaveInfo" method="post"> <p class="contact"><label for="email">Email</label></p> <input id="email" name="email" placeholder="[email protected]" required="" tabindex="1" type="email"> <p class="contact"><label for="username">User Name</label></p> <input id="username" name="username" placeholder="username" required="" tabindex="2" type="text"> <p class="contact"><label for="password">Password</label></p> <input type="password" id="password" name="password" required="" tabindex="3"> <p class="contact"><label for="repassword">Confirm Password</label></p> <input type="password" id="repassword" name="repassword" required=""> <p class="contact"><label for="phone">Mobile Phone</label></p> <input id="phone" name="phone" placeholder="phone number" required="" tabindex="4" type="text"> <br> <p class="contact"><label for="name">Organization Name</label></p> <input id="Orgname" name="name" placeholder="Organization name" required="" tabindex="5" type="text"> <p class="contact"><label for="Address">Address</label></p> <input id="address" name="name" placeholder="Street,Area,city" required="" tabindex="6" type="text"> <br> <!-- <select class="select-style" name="BirthMonth"> --> <label>State</label><br> <select class="select-style" name="BirthMonth"> <% ResultSet rs = null; Connection con = null; PreparedStatement pmst1= null; int countryid = 208; try{ con = DBConnectivity.getOracleDBConnection(); pmst1 = con.prepareStatement(Sqlquery.getRegion()); pmst1.setInt(1, countryid); rs=pmst1.executeQuery(); while(rs.next()){ String name = rs.getString("name"); %> <option value="<%=name %>"><%=name %></option> <% } %> <% }catch(Exception e){ } %> </select><br><br> <p class="contact"> <input id="check" name="name" style="margin-right: 10px" type="checkbox"> <label for="name"> Not Yet Registered GSTIN</label> </p> <p class= "GSTIN"><label for="GSTIN">GSTIN No.</label></p><br> <input id = "GSTINNO" maxlength="15" name= "GSTIN" placeholder="GSTIN No." type ="text"><br><br> <input class="buttom" name="submit" id="submit" tabindex="5" value="Sign me up!" type="submit"> 

SaveInfo.java protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try{ ResultSet rs = null; Connection con = null; PreparedStatement pmst1= null; String Orgname = request.getParameter("Orgname"); String check =request.getParameter("check"); String GSTINNO = request.getParameter("GSTINNO"); con = DBConnectivity.getOracleDBConnection(); int clientid = 1000014; MClient Client = new MClient (Env.getCtx(), clientid, null); 

I want all the values in my servlet class and save that values in database below I am mentioning my web.xml file Kindly help me out

<servlet> <description></description> <display-name>SaveInfo</display-name> <servlet-name>SaveInfo</servlet-name> <servlet-class>com.org.register.SaveInfo</servlet-class> 

<servlet-mapping> <servlet-name>SaveInfo</servlet-name> <url-pattern>/servlet/SaveInfo</url-pattern> </servlet-mapping> 
3
  • You are using wrong name with input tag in your JSP, please verify those. For example there is nothing called Orgname in your JSP. that's why you are getting null for that. Commented Jun 29, 2017 at 11:27
  • You will find a complete explanation about HTML form on mozilla documentation Commented Jun 29, 2017 at 11:33
  • Lina, just for letting you know, you cannot accept two answers for one question here. Only one answer per question is allowed. Commented Jun 29, 2017 at 11:54

3 Answers 3

2

In Servlet you need to get parameters by name attribute, not id.

For example, You have the following,

<input id="Orgname" name="name" placeholder="Organization name" required="" tabindex="5" type="text"> 

Here you have given id to be Orgname and name parameter is name. So in Servlet you will do,

request.getParameter("name"); 

But you are doing,

String Orgname = request.getParameter("Orgname"); 

Secondly, you cannot have same name for two parameters. For both the following you have given name to be name

<input id="Orgname" name="name" placeholder="Organization name" required="" tabindex="5" type="text"> <input id="address" name="name" placeholder="Street,Area,city" required="" tabindex="6" type="text"> <br> 

Give some different name to the parameters.

Sign up to request clarification or add additional context in comments.

Comments

0

The getParameter function of request object works with name attribute. So please replace your jsp with following.

<form id="contactform" action="servlet/SaveInfo" method="post"> <p class="contact"><label for="email">Email</label></p> <input id="email" name="email" placeholder="[email protected]" required="" tabindex="1" type="email"> <p class="contact"><label for="username">User Name</label></p> <input id="username" name="username" placeholder="username" required="" tabindex="2" type="text"> <p class="contact"><label for="password">Password</label></p> <input type="password" id="password" name="password" required="" tabindex="3"> <p class="contact"><label for="repassword">Confirm Password</label></p> <input type="password" id="repassword" name="repassword" required=""> <p class="contact"><label for="phone">Mobile Phone</label></p> <input id="phone" name="phone" placeholder="phone number" required="" tabindex="4" type="text"> <br> <p class="contact"><label for="name">Organization Name</label></p> <input id="Orgname" name="Orgname" placeholder="Organization name" required="" tabindex="5" type="text"> <p class="contact"><label for="Address">Address</label></p> <input id="address" name="address" placeholder="Street,Area,city" required="" tabindex="6" type="text"> <br> <!-- <select class="select-style" name="BirthMonth"> --> <label>State</label><br> <select class="select-style" name="BirthMonth"> <% ResultSet rs = null; Connection con = null; PreparedStatement pmst1= null; int countryid = 208; try{ con = DBConnectivity.getOracleDBConnection(); pmst1 = con.prepareStatement(Sqlquery.getRegion()); pmst1.setInt(1, countryid); rs=pmst1.executeQuery(); while(rs.next()){ String name = rs.getString("name"); %> <option value="<%=name %>"><%=name %></option> <% } %> <% }catch(Exception e){ } %> </select><br><br> <p class="contact"> <input id="check" name="name" style="margin-right: 10px" type="checkbox"> <label for="name"> Not Yet Registered GSTIN</label> </p> <p class= "GSTIN"><label for="GSTIN">GSTIN No.</label></p><br> <input id = "GSTINNO" maxlength="15" name= "GSTIN" placeholder="GSTIN No." type ="text"><br><br> <input class="buttom" name="submit" id="submit" tabindex="5" value="Sign me up!" type="submit"> 

2 Comments

it is not necessary to post the complete code, just saying where annd what is the problem, with an example of correction is enough ;)
Dude I am developer and I understand the pain of other developers, stack overoverflow is a platform where developer come seeking for quick solution. So I write my answer in two parts, 1. pointing out mistake 2. give quick fix (Copy paste).. Hope you understand
0

JSP post parameters using their attribute name. you wrote the wrong attribute name in 3 parameters.

Change:

<input id="check" name="name" <input id="Orgname" name="name" <input id="address" name="name" 

To:

<input id="check" name="check" <input id="Orgname" name="Orgname" <input id="address" name="address" 

2 Comments

You might need to add what is the problem, why is that, what to correction is and do ...
added explanation

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.