Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Error while uploading files in database through plugin

Vedant Kulkarni
Contributor
November 15, 2017

I am getting error after navigating to servlet url is that 

java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided

I correctly written servlet url in .xml file 

CourseSchedule.java

@WebServlet("/CourseSchedule")

@MultipartConfig()
@@Named("CourseSchedule"
public class CourseSchedule extends HttpServlet
{
@ComponentImport
private TemplateRenderer tr;
@ComponentImport
private PageBuilderService pbs;
@ComponentImport
private ActiveObjects ao;

@Inject
public CourseSchedule(TemplateRenderer tr, PageBuilderService pbs,ActiveObjects ao)
{
this.tr=tr;
this.pbs=pbs;
this.ao=ao;
}

@Override
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{

tr.render("/templates/adminOperations/courseSchedule.vm", response.getWriter());

Connection con=null;
Statement st=null;
String msg=null;
String url="jdbc:mysql://localhost:3306/LU_Data?useSSL=false";
String user="root";
String password="123456";

Random rand = new Random();
int n = rand.nextInt(9999) + 1;
String idTemp=(String.valueOf(n));

String semesterName=request.getParameter("semesterName");
Part part=request.getPart("scheduleFile");

PrintWriter pw=response.getWriter();
pw.print(semesterName);

InputStream is=null;

if(part != null)
{
long fileSize=part.getSize();
String fileContent=part.getContentType();
is=part.getInputStream();
}

try
{
Class.forName("com.mysql.cj.jdbc.Driver");

con=DriverManager.getConnection(url, user, password);

PreparedStatement pst=con.prepareStatement("INSERT INTO Course_schedule VALUES(?,?,?)");
pst.setString(1, semesterName);
pst.setString(2, idTemp);

pst.executeUpdate();

if(is!=null)
{
pst.setBinaryStream(3, is, (int) part.getSize());
}

int row=pst.executeUpdate();

if(row==0)
{
pw.print("Error in Uploading a file");
}
else
{
pw.print("File Uploaded Successfully");

}

}
catch(SQLException e)
{
e.printStackTrace();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
}
finally
{
if(con!= null)
try {
con.close();
}catch(SQLException e) {e.printStackTrace();}
}
}

courseSchedule.vm

<html>
<head>
<title>Course Schedule</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<center>
<h1>Upload Course Schedule</h1>
<form action="CourseSchedule" method="post" enctype="multipart/form-data">
<table border="0">
<tr>
<td>Semester Name</td>
<td><input type="text" name="semesterName" size="50"/></td>
</tr>
<tr>
<td>Course Schedule File </td>
<td><input type="file" name="scheduleFile" size="50"/></td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Upload">
</td>
</tr>
</table>
</form>
</center>
<center>
</center>
</body>
</html>

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, mindful member, mindful member badge, atlassian community, community kudos, community giveaway, atlassian swag, community values, empathy and kindness, badge challenge, atlassian learning, community engagement, swag giveaway

Earn a Badge, Win a Prize 🎁

Earning the Mindful Member badge proves you know how to lead with kindness, plus it enters you into a giveaway for exclusive Atlassian swag. Take the quiz, grab the badge, and comment on our announcement article to spread the good vibes!

Start here
AUG Leaders

Atlassian Community Events