I am trying to save data from my registration page to my database but it is not working some how. Does anyone have advise on how I can fix it?
This is my jsp page form.
I am using an embedded derby database.
Any advise would be greatly appreciated.
<form class="form-signin" method="POST" action="newuserservlet">
<input type="text" class="input-block-level" name="firstName" placeholder="First Name">
<input type="text" class="input-block-level" name="lastName" placeholder="Last Name">
<button class="btn btn-large btn-primary" >Sign up</button>
This my servlet:
public class newuserservlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String firstname = request.getParameter("firstName");
String lastname = request.getParameter("lastName");
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
Connection dbConnection = null;
String strUrl = "jdbc:derby:billsdb;create=true";
dbConnection = DriverManager.getConnection(strUrl);
PreparedStatement stmt = dbConnection.prepareStatement("insert into USERDATA values(?,?)");
stmt.setString(1, firstname);
stmt.setString(2, lastname);
int i = stmt.executeUpdate();
if (i > 0) {
out.println("You are successfully registered.....");
}
} catch (Exception ey) {
System.out.println(ey);
}
out.close();
}
Related
I am trying to create a very simple application about login using Servlet & JSP with SQL Database using Eclipse(MARS) IDE.
login.jsp
<body>
<form action="Login"method="post">
Enter username : <input type="text" name="uname"> <br>
Enter password : <input type="password" name="pass"> <br>
<input type="submit" value="login">
</form>
</body>
welcome.jsp
<body>
<%
response.setHeader("Cache-Control", "no-cache,no-store,must-revaildate");
response.setHeader("Pragma","no-cache");
response.setHeader("Expires","0");
if(session.getAttribute("username")==null){
response.sendRedirect("login.jsp");
}
%>
Welcome ${username}
Videos here
<form action="Logout">
<input type="submit" value="Logout">
</form>
</body>
video.jsp
<body>
<%
response.setHeader("Cache-Control", "no-cache,no-store,must-revaildate");
response.setHeader("Pragma","no-cache");
response.setHeader("Expires","0");
if(session.getAttribute("username")==null){
response.sendRedirect("login.jsp");
}
%>
www.thefeind.mp4
</body>
Logout.java
#WebServlet("/Logout")
public class Logout extends HttpServlet {
private static final long serialVersionUID = 1L;
public Logout() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
session.removeAttribute("username");
session.invalidate();
response.sendRedirect("login.jsp");
}
}
LoginDao.java
public class LoginDao {
String sql ="select * from login where uname=? and pass=?";
String url ="jdbc:mysql://localhost:3306/akash";
String username="root";
String password="";
public boolean check(String uname,String pass){
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,username,password);
PreparedStatement st = con.prepareStatement("sql");
st.setString(1,uname);
st.setString(2,pass);
ResultSet rs = st.executeQuery();
if(rs.next()){
return true;
}
}
catch(Exception e){
e.printStackTrace();
}
return false;
}
}
Login.java
public class Login extends HttpServlet {
public Login() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String uname = request.getParameter("uname");
String pass = request.getParameter("pass");
LoginDao dao = new LoginDao();
if(dao.check(uname, pass)){
HttpSession session = request.getSession();
session.setAttribute("username", uname);
response.sendRedirect("welcome.jsp");
}
else{
response.sendRedirect("login.jsp");
}
}
The problem is that I am unable to get login while using correct credentials stored in my database. I am unable to find why this happening in this code?
One issue I see is
PreparedStatement st = con.prepareStatement("sql");
must be
PreparedStatement st = con.prepareStatement(sql);
I am trying to create a register page for users to register new accounts.
I am using signup.jsp page with the register form
Which is then connected to RegisterServlet.java (gets form parameters and inserts parameters into database after connecting to DBConnection.java)
DBConnection contains the try{} of connecting to the mysql database.
I have tried multiple ways of registering a user, but the users information never inserts into database.
signup.jsp:
<form action="RegisterServlet" method="post" onsubmit="return validate()">
<div class="row">
<div class="col-lg-6 col-md-6">
<input type="text" placeholder="First Name" name="fname" class="form-control" />
</div>
<div class="col-lg-6 col-md-6">
<input type="text" placeholder="Last Name" name="lname" class="form-control" />
</div>
</div>
<div>
<input type="text" placeholder="User Name" name="username" class="form-control" />
</div>
<div class="row">
<div class="col-lg-6 col-md-6">
<input type="password" placeholder="Password" name="password" class="form-control" id="pass" name="pass" />
</div>
<div class="col-lg-6 col-md-6">
<input type="password" placeholder="Retype Password" name="confirm_password" class="form-control" id="pass2" name="pass2" />
</div>
<div class="col-lg-6 col-md-6">
<%=(request.getAttribute("errMessage") == null) ? ""
: request.getAttribute("errMessage")%>
</div>
</div>
<div class="pull-left"><button type="submit" class="btn btn-primary">Sign Up</button></div>
</form>
RegisterServlet.java:
#WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public RegisterServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.sendRedirect("login.jsp");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try
{
String fname = request.getParameter("fname");
String lname = request.getParameter("lname");
String username = request.getParameter("username");
String password = request.getParameter("password");
DBConnection db = new DBConnection();
Connection con = db.getCon();
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into user (fname, lname, username, password)values('"+fname+"','"+lname+"','"+username+"','"+password+"')");
System.out.println("data inserted sucessfully");
response.sendRedirect("login.jsp");
} catch (SQLException e)
{
e.printStackTrace();
}
}
}
DBConnection.java
public class DBConnection {
public Connection con;
public Connection getCon(){
try {
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/cultureexchange", "root", "");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return con;
}
}
Sql user table:
fname lname username password
varchar varchar varchar varchar
My login.jsp works so the connection to database must work,
appreciate the help in advance.
try Changing these line
Statement stmt = con.createStatement();
stmt.executeUpdate("insert into user (fname, lname, username, password)values('"+fname+"','"+lname+"','"+username+"','"+password+"')");
to
PreparedStatement stmt = con.prepareStatement("insert into user (fname, lname, username, password)values(?,?,?,?)");
ps.setString(1, fname);
ps.setString(2, lname);
ps.setString(3, username);
ps.setString(4, password);
ps.executeUpdate();
And make sure that you have mysql-j-connector in your lib folder under WEB-INF.
I am working on a simple home library web application using Java EE, Servlets, JSP, and MySQL. My Create, Read, and Delete are working fine but Update is not working. I am not using any form of design patterns, just servlets and POJO. All examples i try to learn from seem to have used MVC and DAO design patterns. Is there any way to achieve the CRUD application without using MVC and DAO patterns? What is the recommended and best practice for such a simple application?
here is code:
UpdateBook.jsp
<%# page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%# page import ="java.util.ArrayList"%>
<%#page import="book.Book"%>
<!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=gbk">
<link rel="stylesheet" type="text/css" href="../css/styles.css" />
<title>Updated Library Collection</title>
</head>
<body>
<div id="container">
<div id="header"><h1 align="center" style="color:blue">Edit Library Collection</h1></div>
<div id="wrapper">
<div id="content" align="center">
<%
request.setCharacterEncoding("gbk");
String ISBN=request.getParameter("Isbn");
String BookTitle=request.getParameter("Title");
String BookAuthor=request.getParameter("Author");
String Category=request.getParameter("Category");
String Description=request.getParameter("Description");
%>
<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center" >
<tr>
<td width="100%" bgcolor="#EAEAEA" colspan="2">
<form name="bookUpdate" action="/homelibrary/UpdateBookServlet" method="POST">
<p>
<label for="Isbn">ISBN: </label>
<input type="text"readonly name="Isbn" id="Isbn" value=<%=ISBN%> >
<br><br>
<label for="Title">Title: </label>
<input type="text" name="Title" id="Title" value=<%=BookTitle%>>
<br><br>
<label for="Author">Author: </label>
<input type="text" name="Author" id="Author" value=<%=BookAuthor%>>
<br><br>
<label for="Category">Category: </label>
<input type="text" name="Category" id="Category" value=<%=Category%>>
<br><br>
<label for="Description">Description: </label>
<input type="text" name="Description" id="Description" value=<%=Description%>>
<br><br>
<p>
<input type="submit" name="Submit" value="Submit" onclick="goto">
<input type="button" name="Cancel" value="Cancel" onclick="javascript:history.go(-1);">
</p>
</form>
</td>
</tr>
</table>
</div>
</div>
<div id="footer" align="center">
<p>© Home Library</p>
</div>
</body>
</html>
UpdateBookServlet.java
package book;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
#WebServlet("/UpdateBookServlet")
public class UpdateBookServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public UpdateBookServlet(){
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//String forward="";
String action = request.getParameter("action");
if (action == ("edit")){
String Isbn = request.getParameter("Isbn");
Book book = null;
try {
book = this.getBookByIsbn(Isbn);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("book", book);
}
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Book/UpdateBook.jsp");
dispatcher.forward(request,response);
}
//#SuppressWarnings("unused")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Book book = new Book();
response.setContentType("text/html");
request.setCharacterEncoding("gbk");
//Get data from form data
String ISBN = request.getParameter("Isbn");
String BookTitle = request.getParameter("Title");
String BookAuthor = request.getParameter("Author");
String Category = request.getParameter("Category");
String Description = request.getParameter("Description");
//#SuppressWarnings("unused")
//PreparedStatement preStmt = null;
//Connection cn =null;
try {
//Create a java MySQL database connection
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/ebookstore";
Connection cn = DriverManager.getConnection(url, "admin", "admin");
PreparedStatement prepStmt= null;
if(ISBN != null)
// create the java MySQL update PreparedStatement
prepStmt = cn.prepareStatement("UPDATE book SET Title=?,Author=?,Category=?,Description=? "+" where Isbn=?");
//String update = "UPDATE book SET Title=?,Author=?,Category=?,Description=? "+" where Isbn=1111";
//prepStmt = cn.prepareStatement(update);
prepStmt.setString(1, book.getTitle());
prepStmt.setString(2, book.getAuthor());
prepStmt.setString(3, book.getCategory());
prepStmt.setString(4, book.getDescription());
prepStmt.setInt(5, Integer.parseInt(book.getISBN()));
//execute the java preparedStatment
prepStmt.executeUpdate();
cn.close();
prepStmt.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
//forwarding from Servlet to a JSP
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/Book/QueryBook.jsp");
dispatcher.forward(request,response);
}
public Book getBookByIsbn(String isbn) throws ClassNotFoundException {
Book book = new Book();
try {
//Create a java MySQL database connection
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/homelib";
Connection cn = DriverManager.getConnection(url, "root", "admin");
PreparedStatement preparedStatement = cn.
prepareStatement("SELECT * FROM book where Isbn=?");
preparedStatement.setString(1, isbn);
ResultSet rs = preparedStatement.executeQuery();
if (rs.next()) {
book.setISBN(rs.getString("Isbn"));
book.setTitle(rs.getString("Title"));
book.setAuthor(rs.getString("Author"));
book.setCategory(rs.getString("Category"));
book.setDescription(rs.getString("Description"));
}
} catch (SQLException e) {
e.printStackTrace();
}
return book;
}
}
Button in QueryBook.jsp
<td>Update</td>
This example is for updating a book's information when a user is logged in on the session
Insert this at the top of your JSP to identify the user on the session
if (session!=null && request.getSession().getAttribute("loggedin") != null) {
if (request.getSession().getAttribute("role").equals("Student")) {
response.sendRedirect("index.jsp");
return;
}
} else {
response.sendRedirect("index.jsp");
return;
} %>
<% if (request.getSession().getAttribute("loggedin") == null) {
response.sendRedirect("index.jsp");
return;
}
BookDTO dto = (BookDTO) request.getSession().getAttribute("book");
Then insert this code below in the JSP to post new data to the servlet
<form method="POST" action="EditBookServlet">
<div class="form-submit">
My Information
<div class="submit">
<div class="form-row">
<div class="x">
<label>Name</label>
<input type="text" class="form" value="<%= dto.getName()%>" name="name">
</div>
<div class="x">
<label>Author</label>
<input type="author" class="form" value="<%= dto.getAuthor()%>" name="author">
</div>
<div class="form x">
<button class="btn" type="submit">Save Changes</button>
</div>
</div>
</div>
</form>
In the EditBookServlet, insert this code
#Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
BookDB db = new BookDB();
BookDTO dto = db.getBookByID(((BookDTO)
request.getSession().getAttribute("book")).getId());
dto.setName(request.getParameter("name"));
dto.setAuthor(request.getParameter("author"));
db.updateBook(dto);
request.getSession().setAttribute("book", dto);
In the StudentDB java file insert this to find the book by Id and then to update the book sql file
public BookDTO getBookByID(int id) {
BookDTO obj = null;
String query = "Select * from book where id=?";
PreparedStatement pst = null;
ResultSet rs = null;
try {
pst = conn.prepareStatement(query);
pst.setInt(1,id);
rs = pst.executeQuery();
if (rs != null) {
if (rs.next()) {
obj = new BookDTO();
obj.setId(rs.getInt(1));
obj.setName(rs.getString(2));
obj.setAuthor(rs.getAuthor(3));
} catch (SQLException ex) {
Logger.getLogger(BookDB.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (rs != null) {
try {
rs.close();
} catch (SQLException ex) {
Logger.getLogger(BookDB.class.getName()).log(Level.SEVERE, null, ex);
}
}
public boolean updateBook(BookDTO obj) {
int affectedRows = 0;
String query = "update `book` set name=? , author=lower(?) where id=?";
PreparedStatement pst = null;
try {
pst = conn.prepareStatement(query);
pst.setString(1,obj.getName());
pst.setString(2,obj.getAuthor());
pst.setInt(10, obj.getId());
System.out.println(pst);
affectedRows = pst.executeUpdate();
} catch (SQLException ex) {
Logger.getLogger(Book.class.getName()).log(Level.SEVERE, null, ex);
}
return affectedRows > 0;
}
You said in your comment:
The update page return with null for all the values.
That is, because you intantiate the Book object In UpdateBookServlet.java
Book book = new Book();
but you set the request parameters into separate string objects:
String ISBN = request.getParameter("Isbn");
String BookTitle = request.getParameter("Title");
String BookAuthor = request.getParameter("Author");
String Category = request.getParameter("Category");
String Description = request.getParameter("Description");
But never use them. Instead you add data from the empty Book object:
prepStmt.setString(1, book.getTitle());
prepStmt.setString(2, book.getAuthor());
prepStmt.setString(3, book.getCategory());
prepStmt.setString(4, book.getDescription());
prepStmt.setInt(5, Integer.parseInt(book.getISBN()));
I have a login page and when i run it, it must check which radio button is checked and check database for that radio button.
When I run the codes I get this error:
HTTP Status 500 - Request processing failed;
nested exception is java.lang.NullPointerException
and
this is my web page:
<form action="/HelloWorldInWeb/login" method="post">
<div class="col-lg-12" id="div3">
<div class="form-group input-group" id="div4">
<div class="input-group-addon "><span class="glyphicon glyphicon-eye-open "></span></div>
<input type="text" class="form-control" name="username" id="textbox1" placeholder="Enter your username">
</div>
<div class="form-group input-group" id="div5">
<div class="input-group-addon "><span class="glyphicon glyphicon-eye-close "></span></div>
<input type="text" class="form-control" name="password" id="textbox2" placeholder="Enter your Password">
</div>
<div class="form-group" id="div6">
<label><input type="radio" name="sign" name="checkbox" value="adminstrator" id="adminstrator" checked>Adminstrator</label>
<label><input type="radio" name="sign" name="checkbox" value="admin" id="admin">Admin</label>
</div>
<div class="align">
<button type="submit" class="btn btn-danger">Ok</button>
</div>
</div>
</form>
this is my controler servelt:
#SuppressWarnings({ "null", "static-access"})
#RequestMapping(value="/login" , method = RequestMethod.POST)
protected void doPost(HttpServletRequest reque, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String username=reque.getParameter("username");
String password=reque.getParameter("password");
String radio=reque.getParameter("checkbox");
if(radio.equals("admin")){
Boolean t = stdDAO.validate(username, password);
if(t){
out.print(username);
out.print(password);
out.print(" username or password succes");
response.sendRedirect("/HelloWorldInWeb/addozvv");
}
else{
out.print(username);
out.print(password);
out.print("Sorry username or password error");
response.sendRedirect("/HelloWorldInWeb/login");
}
out.close();
}else
if(radio.equals("adminstrator")){
Boolean s = stdDAO.validateadm(username, password);
if(s){
out.print(username);
out.print(password);
out.print(" username or password succes");
response.sendRedirect("/HelloWorldInWeb/addozvv");
}
else{
out.print(username);
out.print(password);
out.print("Sorry username or password error");
response.sendRedirect("/HelloWorldInWeb/login");
}
}
}
this is my validates:
public Boolean validate(String username, String password) {
boolean t =false;
try{
Connection con = dataSource.getConnection();
PreparedStatement ps =con.prepareStatement
("select * from admins where username=? and password=?");
ps.setString(1, username);
ps.setString(2, password);
ResultSet rs =ps.executeQuery();
t = rs.next();
}catch(Exception e)
{
e.printStackTrace();
}
return t;
}
#Override
public java.lang.Boolean validateadm(String username, String password) {
boolean s =false;
try{
Connection con = dataSource.getConnection();
PreparedStatement ps =con.prepareStatement
("select * from admin where username=? and password=?");
ps.setString(1, username);
ps.setString(2, password);
ResultSet rs =ps.executeQuery();
s = rs.next();
}catch(Exception e)
{
e.printStackTrace();
}
return s;
}
radio may be null. Use "admin". equals(radio) and "administrator".equals(radio) in your if statements.
I am passing checkbox values, username , file as parameter to a servlet that uses MultipartRequest class from com.orielly.servlet package. I am using the jsp el in my jsp.
my jsp is
<c:set var="currentUser" value="${currentUser}" />
<div class="container">
<div class="panel panel-default" >
<div class="panel-body">
<div class="panel panel-default">
<div class="panel-body">
<form action="ProcessShareFileReq?username="${currentUser}" method="post" enctype="multipart/form-data">
<h4>Upload file here</h4>
<input type="file" class="form-control" required="required" name="file" value=""/>
<h4 class="page header">Share with</h4>
<ul class="list-group">
<c:forEach var="request" items="${requestList}">
<li class="list-group-item title">
<input type="checkbox" name="usersList" value="${request.senderFullName}" /><strong> ${request.senderFullName} </strong>
</li>
</c:forEach>
</ul>
<label class="label" for ="description">Description(Helps other users understand the content of file)</label>
<textarea id="description" name="fileDescription" rows="10" cols="5"></textarea>
<div class="break"></div>
<input type="submit" class="btn btn-default pull-left" value="Upload">
<input type="reset" class="btn btn-default pull-left" value="Reset">
</form>
</div>
</div>
</div>
</div>
</div>
my servlet
#WebServlet("/ProcessShareFileReq")
#MultipartConfig
public class ProcessShareFileReq extends HttpServlet {
private static final long serialVersionUID = 1L;
private String webTempPath;
public void init( ) {
webTempPath= "C://BEProject/Shared";
//webTempPath = getServletContext( ).getRealPath("/") + "data";
}
//Generates current time suitable for oracle timestamp
private static java.sql.Timestamp getCurrentTimeStamp() {
java.util.Date today = new java.util.Date();
return new java.sql.Timestamp(today.getTime());
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Connection currentCon =null;
PreparedStatement ps = null;
int result;
//list of users to share with
String[] UserList = request.getParameterValues("usersList");
//logged-in-user's username
String loggedInUser = request.getParameter("username");
//Shared file's description
String fileDescription = request.getParameter("fileDescription");
//adding path according to sharer's user-name
String userPath = webTempPath + "/" + loggedInUser;
//generate directory
boolean success =( new File(userPath)).mkdirs();
//make directory
if(success) {
System.out.println("Directory: " + webTempPath + " created");
}
//Renames file to the 'sharer_receipent_timestamp' pattern
//Get the uploaded file with multipartRequest
//file limit size of 50 MB
MultipartRequest mpr = new MultipartRequest(request,userPath,50 * 1024 * 1024);
//Database create operations.
Enumeration enum1 = null;
try {
currentCon = ConnectionManager.getConnection();
currentCon.setAutoCommit(true);
for(int i=0;i<UserList.length;i++)
{
String shareFileQuery = "insert into sharedfiles values(share_seq.NEXTVAL,?,?,?,?,?)";
ps = currentCon.prepareStatement(shareFileQuery);
//set the values to put in the query
ps.setString(1, loggedInUser);
ps.setString(2, UserList[i]);
enum1 = mpr.getFileNames( );
String filename = mpr.getFilesystemName((String) enum1.nextElement());
ps.setString(3, filename);
ps.setString(4, fileDescription);
ps.setTimestamp(5, getCurrentTimeStamp());
result=ps.executeUpdate();
if(result>0)
{
System.out.println("Database updated \n");
}
}
} catch (SQLException e) {
e.printStackTrace();
}
response.setContentType("text/html");
request.setAttribute("username", loggedInUser);
RequestDispatcher rd = request.getRequestDispatcher("/SharedFilesHistory");
rd.forward(request, response);
}
I have annotated the servlet with #MultipartConfig so that it can handle the file parameter.
But after adding this it goes upto to the last line and gives error as
java.io.IOException: Corrupt form data: premature ending
com.oreilly.servlet.multipart.MultipartParser.<init>(MultipartParser.java:207)
com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:223)
com.oreilly.servlet.MultipartRequest.<init>(MultipartRequest.java:110)
servlet.share.ProcessShareFileReq.doPost(ProcessShareFileReq.java:104)
javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
filter.authentication.AuthenticationFilter.doFilter(AuthenticationFilter.java:40)
When remvoving the MultipartConfig it gives a NullPointerException at the for loop since 'UserList' is null since no value is received in servlet from jsp.
Please help
I remember having some little issues when working with MultipartRequest (seems related to some bugs), which made me drop its usage in favor of the native Servelt 3.x Part and which may be a good alternative for you:
Inside your doPost method you can retrieve your file as a Part of the request using its name:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
//...
Part filePart = request.getPart("file"); // Retrieves <input type="file" class="form-control" required="required" name="file" value=""/>
InputStream fileContent = filePart.getInputStream(); // Get an InputStream then let the file make its way to your storage location
}