use of scriptlets(
<% %>
) in JSP highly discouraged, use JSTL(<c:tags
) or Expression Language(${}
)
to use JSTL in your jsp download jstl.x.x.jar file and add it to your buildpath.
then, add this
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
in top of jsp.
to resolve form action url you have:
<%=Constants.WEB_APP_NAME%><%=Constants.SERVLET_NAME%>
no need of any constants for that, instead use <c:url
tag to resolve url like:
<c:url value="/yourServletUrl" var="postUrl"/>
<form action="${postUrl}" method="post" ...
i am getting null with uploadfilename in action parameter
because, you accessing javascript variable in html(&uploadfilename="+filename+"
), instead do like:
jsp:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<title>your title</title>
</head>
<body>
<c:url value="/yourServletUrl" var="postUrl"/>
<form id="AttachmentsForm"
method="post"
onSubmit="showFileName()"
action="${postUrl}para=ajaxRefTabUpload&action=add"
enctype="multipart/form-data">
<table class="innerBorderTable" width="100%">
<tr>
<td>Attach New File:</td>
<td>
<input type="file" name="uploadFile" width="120">
<input type="submit" class="button" value="Add Attachment">
</td>
</tr>
</table>
</form>
<script type="text/javascript">
function showFileName(e) {
if (e.preventDefault)
e.preventDefault();
var filename = document.getElementById("uploadFile");
alert('fileName: '+filename);
//here, attach filename to from action and continue your form submition by AJAX
// You must return false to prevent the default form behavior
return false;
}
}
</script>
</body>
</html>