I Have a
JSP form which cals
servlet, that servelt uploads file in directory and insert other values of form in database. My uploading of files is working perfect, in that servlet now i am trying to call values of form through getParameter to insert in database. But it oesn't get the values and prints NULL.
please help
This is my Form
<form name= "projectinfo" method ="Post" action="saveFiles.servlet" title="theEventForm" ENCtype="multipart/form-data">
<input type="HIDDEN" name="Project" value="<%=projectname%>" size="100"/>
<input type="HIDDEN" name="Event_type" value="<%=eventtype%>" size="100"/>
<table border="0" cellspacing="4" cellpadding="0">
<tr>
<td align="right" width='200'>Event Type: </td>
<td align="left">
<select name='eventtype' onchange='eventtypeselect(this)'>
<option value=''></option>
<option value=''>TechPreScreen</option>
<option value=''>Passport1</span></option>
<option value=''>Passport2</option>
<option value=''>Passport3</option>
<option value=''>Passport4</option>
<option value=''>DesignReview</span></option>
</select>
</td>
</tr>
<%
// Declare some variables to use across multiple
java blocks in this form
String attendees = "" ;
String notehistory ="";
boolean goteventtype = false ;
ProjectEvent pe = null;
String [] filenames = new String[0];
if ( eventtype != null && projectname !=null)
{
pe = db.getEventType(eventtype,projectname);
if (pe != null)
{
filenames = pe.getFileNames();
attendees = pe.getParticipants();
notehistory =pe.getNoteHistory();
goteventtype = true;
}
}
%>
</td>
</tr>
<tr>
<td align="right">Key contacts or participants:</td>
<td align ="left"><textarea name="participants" cols='45' rows='1'><% out.write (attendees);%></textarea></td>
</tr>
<tr>
<td align="right">IT Architecture Approved ?: </td>
<td align="left" >
<input type="checkbox" name='approved' checked="checked">
</td>
</tr>
<tr>
<td align="right">Notes/Issues/Open items: </td>
<td align="left"> <textarea name="notes" cols='50' rows='1'></textarea>
</td>
</tr>
<tr>
<td align="right">Notes History: </td>
<td align="left"><textarea name="notehistory" cols='50' rows='2' disabled='true'><% out.write(notehistory); %></textarea></td>
</tr>
<tr>
<table>
<td align="right">Attachments:</td>
<td align="left">
<table>
<tr><td>
<%
int filesdisplay = filenames.length;
for(int i =0;i<filesdisplay;i++)
{
out.write("<a href='/itads/docs/" + projectname + "/" + eventtype +"/"+filenames[i]+"'>" + filenames[i] +"</a><br>");
}
%>
</td></tr>
</table>
<table id="theAttachmentTable" border="0" cellspacing="0" cellpadding="0">
<tr><td><input type="FILE" name="FILE1" size="80" onchange="javascript:addNewAttachmentField();"/></td></tr>
</table>
</td></tr>
<td></td>
</table>
<tr>
<td align="center">
<input type="button" name="refresh" value='Refresh'>
</td>
<td align="center">
<td align="center">
<input type="submit" name="savedoc" value="Save ">
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
This is my Servlet
package servlet;
import DBAccess.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import javax.sql.*;
import javax.servlet.*;
import javax.naming.*;
import javax.servlet.http.*;
import com.jspsmart.upload.*;
public class saveFiles extends HttpServlet {
/*boolean p = false;*/
char squote ='\'';
char dquote ='\'';
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try {
ServletContext context = getServletContext();
ServletConfig config = getServletConfig();
String sessionId = request.getSession().getId();
java.io.File tempdir = (java.io.File) context.getAttribute( "javax.servlet.context.tempdir" );
out.write( "<html>" );
out.write( "<head>" );
out.write( "<title>Upload Files Servlet [" + request.getServerName() + "]</title>" );
out.write( "</head>" );
out.write( "<body>" );
ResourceBundle rb = ResourceBundle.getBundle("Project");
String rootdir_name = rb.getString("projectDocRootDirectory");
if ( rootdir_name.equals("TEMP") )
{
rootdir_name = tempdir.getPath() + "\\upload";
}
RequestDispatcher dispatcher = context.getRequestDispatcher( "/header.jsp" );;
dispatcher.include(request, response);
out.write( "<h1>Upload Files!</h1>" );
int count=0;
com.jspsmart.upload.SmartUpload mySmartUpload = new com.jspsmart.upload.SmartUpload();
mySmartUpload.initialize(config,request,response);
//mySmartUpload.setTotalMaxFileSize(10000000);
//mySmartUpload.setMaxFileSize(10000000);
mySmartUpload.upload();
String project_name = mySmartUpload.getRequest().getParameter("Project");
String eventtype_name = mySmartUpload.getRequest().getParameter("Event_type");
String subdir_name=project_name +"/"+ eventtype_name;
if ( subdir_name == null )
{
subdir_name = ".";
}
String dir_name = rootdir_name + "/" + subdir_name;
System.out.println(dir_name);
java.io.File dir = (java.io.File) new java.io.File( dir_name );
if ( !dir.exists() )
{
dir.mkdirs();
}
count = mySmartUpload.save( dir.getPath() );
out.println( "<p>" + count + " file(s) uploaded to " + dir.getPath() + ".</p>" );
out.println( "<ul>" );
com.jspsmart.upload.Files files = mySmartUpload.getFiles();
out.println( "<ul>" );
for ( int i=0; i<count; i++ )
{
com.jspsmart.upload.File f = files.getFile(i);
out.println( "<li>" + f.getFileName() + " [" + f.getSize() + " bytes]</li>" );
}
out.println( "</ul>" );
dispatcher = context.getRequestDispatcher( "/footer.jsp" );
dispatcher.include(request, response);
out.write( "</body>" );
out.write( "</html>" );
}
catch (Exception e) {
log(e.getMessage());
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String Attendees = request.getParameter("participants");
String NoteHistory = request.getParameter("notehistory");
System.out.println(Attendees); /* this print null on console*/
System.out.println(NoteHistory);/* this prints null on console*/
ProjectDatabase db = new ProjectDatabase();
String ANames =db.changeQuote(Attendees,squote,dquote);
String Notes =db.changeQuote(NoteHistory,squote,dquote);
db.createEvent(ANames,Notes);
doGet(request, response);
}
}