On Servlet the values are null when Post method is used but when Get method is used then its fine
i am using jsp page to insert some value but when the parameters get to the servelet the values received are null when I am using Post method but when Get method is used then it works fine.
request.getParameter() is returning null value when post method is used but when get method is used it works fine and the values get inserted
anyone have idea how to fix this???
//Jsp Page
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="insert.css">
<title>Database Update</title>
</head>
<body>
<h1 class="main-header">Enter the Details</h1>
<div class="fullbody">
<form action="Insert" method="post" enctype="multipart/form-data">
<div class="text">
<b>Stuid:</b>
<input type="text" placeholder="stuid" name="stuid" pattern=[0-9]{1,} title="can only have numeric value" required>
<b>Student Name:</b>
<input type="text" placeholder="student name" name="name" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Student Mobile no.:</b>
<input type="text" placeholder="student mobile no." name="stumob" pattern=[0-9]{10} title="10 digit number" required>
<br>
<b>Father's Name:</b>
<input type="text" placeholder="Father's name" name="fname" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Father's Mobile no.:</b>
<input type="text" placeholder="father's mobile no." name="fmob" pattern=[0-9]{10} title="10 digit number" required>
<br>
<b>Mother's Name:</b>
<input type="text" placeholder="Mother's name" name="mname" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Gender:</b>
<input type="radio" value="male" name="gender" required> Male
<input type="radio" value="female" name="gender"> Female
<b>Date of Birth:</b>
<input type="date" placeholder="dd/mm/yyyy" name="dob" required>
<b>Address:</b>
<input type="text" placeholder="address" name="addr" required>
<br>
<b>Programme:</b>
<select name="programme">
<option value="B.tech">B.tech</option>
<option value="M.tech">M.tech</option>
<option value="BBA">BBA</option>
<option value="BCA">BCA</option>
</select>
<b>Branch Code:</b>
<input type="text" placeholder="branch code" name="branch" pattern=[A-Za-z]{3,6} title="can only have alphabet" required>
<b>Year:</b>
<select name="year">
<option value="1st">1st</option>
<option value="2nd">2nd</option>
<option value="3rd">3rd</option>
<option value="4th">4th</option>
</select>
<br>
<b>Photo Upload:</b>
<input type="file" name="photo" required>
</div>
<div class="submit">
<input type="Submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
//servlet
package java_app1;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Insert extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
String stuid=request.getParameter("stuid");
String name=request.getParameter("name");
String stumob=request.getParameter("stumob");
String fname=request.getParameter("fname");
String fmob=request.getParameter("fmob");
String mname=request.getParameter("mname");
String gender=request.getParameter("gender");
String dob=request.getParameter("dob");
String addr=request.getParameter("addr");
String programme=request.getParameter("programme");
String branch=request.getParameter("branch");
String year=request.getParameter("year");
String photo=request.getParameter("photo");
PrintWriter out=response.getWriter();
out.println(stuid);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","ankit");
PreparedStatement ps=con.prepareStatement("insert into student.stulog values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
ps.setString(1,stuid);
ps.setString(2,fmob);
ps.setString(3,name);
ps.setString(4,stumob);
ps.setString(5,fname);
ps.setString(6,fmob);
ps.setString(7,mname);
ps.setString(8,gender);
ps.setString(9,dob);
ps.setString(10,addr);
ps.setString(11,programme);
ps.setString(12,year);
ps.setString(13,branch);
ps.setString(14,photo);
int rs=ps.executeUpdate();
if(rs!=0)
{
out.println("[SUCCESS] RECORDS INSERTED SCUCCESSFULLY");
RequestDispatcher rd=request.getRequestDispatcher("/dashboard.jsp");
rd.include(request, response);
}
else
{
out.println("[FAILURE] RECORDS NOT INSERTED");
RequestDispatcher rd=request.getRequestDispatcher("/dashboard.jsp");
rd.include(request, response);
}
}catch (Exception e)
{
out.println("Error:"+e);
e.printStackTrace();
}
}
}
jsp servlets
add a comment |
i am using jsp page to insert some value but when the parameters get to the servelet the values received are null when I am using Post method but when Get method is used then it works fine.
request.getParameter() is returning null value when post method is used but when get method is used it works fine and the values get inserted
anyone have idea how to fix this???
//Jsp Page
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="insert.css">
<title>Database Update</title>
</head>
<body>
<h1 class="main-header">Enter the Details</h1>
<div class="fullbody">
<form action="Insert" method="post" enctype="multipart/form-data">
<div class="text">
<b>Stuid:</b>
<input type="text" placeholder="stuid" name="stuid" pattern=[0-9]{1,} title="can only have numeric value" required>
<b>Student Name:</b>
<input type="text" placeholder="student name" name="name" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Student Mobile no.:</b>
<input type="text" placeholder="student mobile no." name="stumob" pattern=[0-9]{10} title="10 digit number" required>
<br>
<b>Father's Name:</b>
<input type="text" placeholder="Father's name" name="fname" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Father's Mobile no.:</b>
<input type="text" placeholder="father's mobile no." name="fmob" pattern=[0-9]{10} title="10 digit number" required>
<br>
<b>Mother's Name:</b>
<input type="text" placeholder="Mother's name" name="mname" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Gender:</b>
<input type="radio" value="male" name="gender" required> Male
<input type="radio" value="female" name="gender"> Female
<b>Date of Birth:</b>
<input type="date" placeholder="dd/mm/yyyy" name="dob" required>
<b>Address:</b>
<input type="text" placeholder="address" name="addr" required>
<br>
<b>Programme:</b>
<select name="programme">
<option value="B.tech">B.tech</option>
<option value="M.tech">M.tech</option>
<option value="BBA">BBA</option>
<option value="BCA">BCA</option>
</select>
<b>Branch Code:</b>
<input type="text" placeholder="branch code" name="branch" pattern=[A-Za-z]{3,6} title="can only have alphabet" required>
<b>Year:</b>
<select name="year">
<option value="1st">1st</option>
<option value="2nd">2nd</option>
<option value="3rd">3rd</option>
<option value="4th">4th</option>
</select>
<br>
<b>Photo Upload:</b>
<input type="file" name="photo" required>
</div>
<div class="submit">
<input type="Submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
//servlet
package java_app1;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Insert extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
String stuid=request.getParameter("stuid");
String name=request.getParameter("name");
String stumob=request.getParameter("stumob");
String fname=request.getParameter("fname");
String fmob=request.getParameter("fmob");
String mname=request.getParameter("mname");
String gender=request.getParameter("gender");
String dob=request.getParameter("dob");
String addr=request.getParameter("addr");
String programme=request.getParameter("programme");
String branch=request.getParameter("branch");
String year=request.getParameter("year");
String photo=request.getParameter("photo");
PrintWriter out=response.getWriter();
out.println(stuid);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","ankit");
PreparedStatement ps=con.prepareStatement("insert into student.stulog values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
ps.setString(1,stuid);
ps.setString(2,fmob);
ps.setString(3,name);
ps.setString(4,stumob);
ps.setString(5,fname);
ps.setString(6,fmob);
ps.setString(7,mname);
ps.setString(8,gender);
ps.setString(9,dob);
ps.setString(10,addr);
ps.setString(11,programme);
ps.setString(12,year);
ps.setString(13,branch);
ps.setString(14,photo);
int rs=ps.executeUpdate();
if(rs!=0)
{
out.println("[SUCCESS] RECORDS INSERTED SCUCCESSFULLY");
RequestDispatcher rd=request.getRequestDispatcher("/dashboard.jsp");
rd.include(request, response);
}
else
{
out.println("[FAILURE] RECORDS NOT INSERTED");
RequestDispatcher rd=request.getRequestDispatcher("/dashboard.jsp");
rd.include(request, response);
}
}catch (Exception e)
{
out.println("Error:"+e);
e.printStackTrace();
}
}
}
jsp servlets
add a comment |
i am using jsp page to insert some value but when the parameters get to the servelet the values received are null when I am using Post method but when Get method is used then it works fine.
request.getParameter() is returning null value when post method is used but when get method is used it works fine and the values get inserted
anyone have idea how to fix this???
//Jsp Page
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="insert.css">
<title>Database Update</title>
</head>
<body>
<h1 class="main-header">Enter the Details</h1>
<div class="fullbody">
<form action="Insert" method="post" enctype="multipart/form-data">
<div class="text">
<b>Stuid:</b>
<input type="text" placeholder="stuid" name="stuid" pattern=[0-9]{1,} title="can only have numeric value" required>
<b>Student Name:</b>
<input type="text" placeholder="student name" name="name" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Student Mobile no.:</b>
<input type="text" placeholder="student mobile no." name="stumob" pattern=[0-9]{10} title="10 digit number" required>
<br>
<b>Father's Name:</b>
<input type="text" placeholder="Father's name" name="fname" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Father's Mobile no.:</b>
<input type="text" placeholder="father's mobile no." name="fmob" pattern=[0-9]{10} title="10 digit number" required>
<br>
<b>Mother's Name:</b>
<input type="text" placeholder="Mother's name" name="mname" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Gender:</b>
<input type="radio" value="male" name="gender" required> Male
<input type="radio" value="female" name="gender"> Female
<b>Date of Birth:</b>
<input type="date" placeholder="dd/mm/yyyy" name="dob" required>
<b>Address:</b>
<input type="text" placeholder="address" name="addr" required>
<br>
<b>Programme:</b>
<select name="programme">
<option value="B.tech">B.tech</option>
<option value="M.tech">M.tech</option>
<option value="BBA">BBA</option>
<option value="BCA">BCA</option>
</select>
<b>Branch Code:</b>
<input type="text" placeholder="branch code" name="branch" pattern=[A-Za-z]{3,6} title="can only have alphabet" required>
<b>Year:</b>
<select name="year">
<option value="1st">1st</option>
<option value="2nd">2nd</option>
<option value="3rd">3rd</option>
<option value="4th">4th</option>
</select>
<br>
<b>Photo Upload:</b>
<input type="file" name="photo" required>
</div>
<div class="submit">
<input type="Submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
//servlet
package java_app1;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Insert extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
String stuid=request.getParameter("stuid");
String name=request.getParameter("name");
String stumob=request.getParameter("stumob");
String fname=request.getParameter("fname");
String fmob=request.getParameter("fmob");
String mname=request.getParameter("mname");
String gender=request.getParameter("gender");
String dob=request.getParameter("dob");
String addr=request.getParameter("addr");
String programme=request.getParameter("programme");
String branch=request.getParameter("branch");
String year=request.getParameter("year");
String photo=request.getParameter("photo");
PrintWriter out=response.getWriter();
out.println(stuid);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","ankit");
PreparedStatement ps=con.prepareStatement("insert into student.stulog values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
ps.setString(1,stuid);
ps.setString(2,fmob);
ps.setString(3,name);
ps.setString(4,stumob);
ps.setString(5,fname);
ps.setString(6,fmob);
ps.setString(7,mname);
ps.setString(8,gender);
ps.setString(9,dob);
ps.setString(10,addr);
ps.setString(11,programme);
ps.setString(12,year);
ps.setString(13,branch);
ps.setString(14,photo);
int rs=ps.executeUpdate();
if(rs!=0)
{
out.println("[SUCCESS] RECORDS INSERTED SCUCCESSFULLY");
RequestDispatcher rd=request.getRequestDispatcher("/dashboard.jsp");
rd.include(request, response);
}
else
{
out.println("[FAILURE] RECORDS NOT INSERTED");
RequestDispatcher rd=request.getRequestDispatcher("/dashboard.jsp");
rd.include(request, response);
}
}catch (Exception e)
{
out.println("Error:"+e);
e.printStackTrace();
}
}
}
jsp servlets
i am using jsp page to insert some value but when the parameters get to the servelet the values received are null when I am using Post method but when Get method is used then it works fine.
request.getParameter() is returning null value when post method is used but when get method is used it works fine and the values get inserted
anyone have idea how to fix this???
//Jsp Page
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="insert.css">
<title>Database Update</title>
</head>
<body>
<h1 class="main-header">Enter the Details</h1>
<div class="fullbody">
<form action="Insert" method="post" enctype="multipart/form-data">
<div class="text">
<b>Stuid:</b>
<input type="text" placeholder="stuid" name="stuid" pattern=[0-9]{1,} title="can only have numeric value" required>
<b>Student Name:</b>
<input type="text" placeholder="student name" name="name" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Student Mobile no.:</b>
<input type="text" placeholder="student mobile no." name="stumob" pattern=[0-9]{10} title="10 digit number" required>
<br>
<b>Father's Name:</b>
<input type="text" placeholder="Father's name" name="fname" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Father's Mobile no.:</b>
<input type="text" placeholder="father's mobile no." name="fmob" pattern=[0-9]{10} title="10 digit number" required>
<br>
<b>Mother's Name:</b>
<input type="text" placeholder="Mother's name" name="mname" pattern="[A-Za-z ]{1,45}" title="can only have alphabet and space" required>
<b>Gender:</b>
<input type="radio" value="male" name="gender" required> Male
<input type="radio" value="female" name="gender"> Female
<b>Date of Birth:</b>
<input type="date" placeholder="dd/mm/yyyy" name="dob" required>
<b>Address:</b>
<input type="text" placeholder="address" name="addr" required>
<br>
<b>Programme:</b>
<select name="programme">
<option value="B.tech">B.tech</option>
<option value="M.tech">M.tech</option>
<option value="BBA">BBA</option>
<option value="BCA">BCA</option>
</select>
<b>Branch Code:</b>
<input type="text" placeholder="branch code" name="branch" pattern=[A-Za-z]{3,6} title="can only have alphabet" required>
<b>Year:</b>
<select name="year">
<option value="1st">1st</option>
<option value="2nd">2nd</option>
<option value="3rd">3rd</option>
<option value="4th">4th</option>
</select>
<br>
<b>Photo Upload:</b>
<input type="file" name="photo" required>
</div>
<div class="submit">
<input type="Submit" value="Submit">
</div>
</form>
</div>
</body>
</html>
//servlet
package java_app1;
import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Insert extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
String stuid=request.getParameter("stuid");
String name=request.getParameter("name");
String stumob=request.getParameter("stumob");
String fname=request.getParameter("fname");
String fmob=request.getParameter("fmob");
String mname=request.getParameter("mname");
String gender=request.getParameter("gender");
String dob=request.getParameter("dob");
String addr=request.getParameter("addr");
String programme=request.getParameter("programme");
String branch=request.getParameter("branch");
String year=request.getParameter("year");
String photo=request.getParameter("photo");
PrintWriter out=response.getWriter();
out.println(stuid);
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/student","root","ankit");
PreparedStatement ps=con.prepareStatement("insert into student.stulog values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
ps.setString(1,stuid);
ps.setString(2,fmob);
ps.setString(3,name);
ps.setString(4,stumob);
ps.setString(5,fname);
ps.setString(6,fmob);
ps.setString(7,mname);
ps.setString(8,gender);
ps.setString(9,dob);
ps.setString(10,addr);
ps.setString(11,programme);
ps.setString(12,year);
ps.setString(13,branch);
ps.setString(14,photo);
int rs=ps.executeUpdate();
if(rs!=0)
{
out.println("[SUCCESS] RECORDS INSERTED SCUCCESSFULLY");
RequestDispatcher rd=request.getRequestDispatcher("/dashboard.jsp");
rd.include(request, response);
}
else
{
out.println("[FAILURE] RECORDS NOT INSERTED");
RequestDispatcher rd=request.getRequestDispatcher("/dashboard.jsp");
rd.include(request, response);
}
}catch (Exception e)
{
out.println("Error:"+e);
e.printStackTrace();
}
}
}
jsp servlets
jsp servlets
asked Jul 10 '17 at 16:30
ankitjaiswalankitjaiswal
394
394
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
try this way it work fine for me
in jsp:
<form action="${pageContext.request.contextPath}/binod" method="post">
<input type="text" name="firstName"/>
<input type="submit" value="login"/>
</form>
in servlet:
@WebServlet(urlPatterns="/binod")
public class Test extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("your name is"+req.getParameter("firstName"));
}
}
You must override
doPost
method from HttpServlet
add a comment |
step 1:
import
javax.servlet.annotation.MultipartConfig;
step 2:
add annotation
@MultipartConfig(maxFileSize = 16177215) //Length of the file
after webServlet,urlPatterns
That's it !!
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45017304%2fon-servlet-the-values-are-null-when-post-method-is-used-but-when-get-method-is-u%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this way it work fine for me
in jsp:
<form action="${pageContext.request.contextPath}/binod" method="post">
<input type="text" name="firstName"/>
<input type="submit" value="login"/>
</form>
in servlet:
@WebServlet(urlPatterns="/binod")
public class Test extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("your name is"+req.getParameter("firstName"));
}
}
You must override
doPost
method from HttpServlet
add a comment |
try this way it work fine for me
in jsp:
<form action="${pageContext.request.contextPath}/binod" method="post">
<input type="text" name="firstName"/>
<input type="submit" value="login"/>
</form>
in servlet:
@WebServlet(urlPatterns="/binod")
public class Test extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("your name is"+req.getParameter("firstName"));
}
}
You must override
doPost
method from HttpServlet
add a comment |
try this way it work fine for me
in jsp:
<form action="${pageContext.request.contextPath}/binod" method="post">
<input type="text" name="firstName"/>
<input type="submit" value="login"/>
</form>
in servlet:
@WebServlet(urlPatterns="/binod")
public class Test extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("your name is"+req.getParameter("firstName"));
}
}
You must override
doPost
method from HttpServlet
try this way it work fine for me
in jsp:
<form action="${pageContext.request.contextPath}/binod" method="post">
<input type="text" name="firstName"/>
<input type="submit" value="login"/>
</form>
in servlet:
@WebServlet(urlPatterns="/binod")
public class Test extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("your name is"+req.getParameter("firstName"));
}
}
You must override
doPost
method from HttpServlet
answered Jul 10 '17 at 17:40
Binod PantBinod Pant
139113
139113
add a comment |
add a comment |
step 1:
import
javax.servlet.annotation.MultipartConfig;
step 2:
add annotation
@MultipartConfig(maxFileSize = 16177215) //Length of the file
after webServlet,urlPatterns
That's it !!
add a comment |
step 1:
import
javax.servlet.annotation.MultipartConfig;
step 2:
add annotation
@MultipartConfig(maxFileSize = 16177215) //Length of the file
after webServlet,urlPatterns
That's it !!
add a comment |
step 1:
import
javax.servlet.annotation.MultipartConfig;
step 2:
add annotation
@MultipartConfig(maxFileSize = 16177215) //Length of the file
after webServlet,urlPatterns
That's it !!
step 1:
import
javax.servlet.annotation.MultipartConfig;
step 2:
add annotation
@MultipartConfig(maxFileSize = 16177215) //Length of the file
after webServlet,urlPatterns
That's it !!
answered Nov 24 '18 at 20:33
dubking Indiadubking India
134
134
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f45017304%2fon-servlet-the-values-are-null-when-post-method-is-used-but-when-get-method-is-u%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown