When i am selecting a Pic and clicking on upload getting internal server error. while debugging the line at which i am getting internal server error is in Register class i.e
ImgClipUtil clipUtil = new ImgClipUtil(Constants.IMG_STORE_URL + "/" + _photoName + Constants.IMG_TYPE_JPG);
UploadPhoto.jsp
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglib.jsp"%>
<script type="text/javascript">
$(document).ready(function(e) {
$('.uploadImage').click(function(e) {
$('.upload').find('input[type=file]').trigger('click');
});
$('.upload').find('input[type=file]').change(function(e) {
$('.uploadImage').val($(this)[0].files[0].name);
alert($(this)[0].files[0].name);
});
});</script>
<div class="bodyMiddle fullWidth">
<h1 class="h2"><s:text name="regist.title.page"/></h1>
<ul class="rBrdcrumb">
<li><a href="#" onclick="javascript:void();"><s:text name="regist.personal.information.title"/></a></li>
<li><a href="#" onclick="javascript:void();"><s:text name="regist.contact.title"/></a></li>
<li><a href="#" onclick="javascript:void();"><s:text name="regist.health.title"/></a></li>
<li class="active"><a href="#" onclick="javascript:void();"><s:text name="regist.upload.photo.title"/></a></li>
</ul>
<div class="row registration">
<form autocomplete="off" action="/regist/finishRegistration.jhtml" id="frmUploadPhoto" data-toggle="validator" role="form" method="post">
<div class="col-sm-12">
<h3><s:text name="regist.upload.photo.page.title"/></h3>
</div>
<div class="col-sm-5">
<div class="form-group">
<div class="upload">
<input type="text" class="form-control uploadImage" placeholder="<s:text name="regist.upload.photo.label.browse.photo"/>">
<input class="btn red-gradient" type="button" id="btnUploadPhoto" value="<s:text name="regist.upload.photo.label.button.upload"/>">
<input type="file" name="photo" hidden="">
</div>
</div>
<p><s:text name="regist.upload.photo.message.constraint.size"/></p>
</div>
<div class="col-sm-7">
<div class="uploadImageDemo"><img id="imgUploadedPhoto" src="/static/new_images/pic_20.jpg" alt=""/></div>
</div>
<div class="col-sm-12">
<input type="submit" class="btn red-gradient" value="<s:text name="regist.upload.photo.label.button.finish"/>"/>
</div>
</form>
</div>
</div>
When i am selecting a Pic and clicking on upload getting internal server error. while debugging the line at which i am getting internal server error is in Register class i.e ImgClipUtil clipUtil = new ImgClipUtil(Constants.IMG_STORE_URL + "/" + _photoName + Constants.IMG_TYPE_JPG);
UploadPhoto.jsp
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common/taglib.jsp"%>
<script type="text/javascript">
$(document).ready(function(e) {
$('.uploadImage').click(function(e) {
$('.upload').find('input[type=file]').trigger('click');
});
$('.upload').find('input[type=file]').change(function(e) {
$('.uploadImage').val($(this)[0].files[0].name);
alert($(this)[0].files[0].name);
});
});</script>
<div class="bodyMiddle fullWidth">
<h1 class="h2"><s:text name="regist.title.page"/></h1>
<ul class="rBrdcrumb">
<li><a href="#" onclick="javascript:void();"><s:text name="regist.personal.information.title"/></a></li>
<li><a href="#" onclick="javascript:void();"><s:text name="regist.contact.title"/></a></li>
<li><a href="#" onclick="javascript:void();"><s:text name="regist.health.title"/></a></li>
<li class="active"><a href="#" onclick="javascript:void();"><s:text name="regist.upload.photo.title"/></a></li>
</ul>
<div class="row registration">
<form autocomplete="off" action="/regist/finishRegistration.jhtml" id="frmUploadPhoto" data-toggle="validator" role="form" method="post">
<div class="col-sm-12">
<h3><s:text name="regist.upload.photo.page.title"/></h3>
</div>
<div class="col-sm-5">
<div class="form-group">
<div class="upload">
<input type="text" class="form-control uploadImage" placeholder="<s:text name="regist.upload.photo.label.browse.photo"/>">
<input class="btn red-gradient" type="button" id="btnUploadPhoto" value="<s:text name="regist.upload.photo.label.button.upload"/>">
<input type="file" name="photo" hidden="">
</div>
</div>
<p><s:text name="regist.upload.photo.message.constraint.size"/></p>
</div>
<div class="col-sm-7">
<div class="uploadImageDemo"><img id="imgUploadedPhoto" src="/static/new_images/pic_20.jpg" alt=""/></div>
</div>
<div class="col-sm-12">
<input type="submit" class="btn red-gradient" value="<s:text name="regist.upload.photo.label.button.finish"/>"/>
</div>
</form>
</div>
</div>
Register.java
public
String uploadPhoto_New() {
String _locale = LocaleUtil.getUserLocale();
String basePath = ActionUtil.getRequest().getScheme() + "://" + ActionUtil.getRequest().getServerName() + ":" + ActionUtil.getRequest().getServerPort();
boolean hasError = false;
if (photo == null) {
hasError = true;
}
if (hasError) {
String json = "{\"photoUrl\":null}";
ActionUtil.printStr(json);
return null;
}
try {
//ä¿�å˜ç”¨æˆ·ä¸Šä¼ 的原始图片
String _photoName = ImgUploadUtil.uploadFile(photo);
//å¯¹ç”¨æˆ·ä¸Šä¼ çš„åŽŸå§‹å›¾ç‰‡æŒ‰ç‰¹å®šçš„å°ºå¯¸åŽ‹ç¼©
ImgClipUtil clipUtil = new ImgClipUtil(Constants.IMG_STORE_URL + "/" + _photoName + Constants.IMG_TYPE_JPG);
String _resizedPhotoName = _photoName + "";
clipUtil.resize(Constants.IMG_STORE_URL + "/" + _resizedPhotoName + Constants.IMG_TYPE_JPG, 150);
MemberDto memberDtoFromSession = (MemberDto) ActionUtil.getSession().get(Constants.MEMBER_DTO);
memberDtoFromSession.setPhoto(_resizedPhotoName);
String json = "{\"photoUrl\":\"" + basePath + Constants.IMG_ACCESS_URL + "/" + _resizedPhotoName + Constants.IMG_TYPE_JPG + "\"}";
ActionUtil.printStr(json);
return null;
} catch (Exception ex) {
loger.error(ex, ex);
String json = "{\"photoUrl\":null}";
ActionUtil.printStr(json);
return null;
}
}
ImgClipUtil.java
public ImgClipUtil(String _path) {
try {
info = new ImageInfo(_path);
info.setCompression(CompressionType.JPEGCompression);
info.setPreviewType(PreviewType.JPEGPreview);
calculateSize(_path);
} catch (MagickException e) {
e.printStackTrace();
}
}