image insert 2nd way( Form submit by jquery ) :
1.jsp page :
<form id="myForm" action="javascript:insertRoomTypeModalClose();" class="form-horizontal" method="post" enctype="multipart/form-data">
<div class="modal-body">
<!-- START PAGE CONTENT-->
<!-- BEGIN EXAMPLE TABLE widget-->
<div class="widget red">
<div class="widget-title">
<!--h4><i class="icon-reorder"></i> Data Table</h4-->
<!--span class="tools">
<a href="javascript:;" class="icon-chevron-down"></a>
<a href="javascript:;" class="icon-remove"></a>
</span-->
</div>
<div class="widget-body">
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="31%" style="text-align:right;font-family:Arial;font-size:12px;font-weight:bold;color:#000;">Search : </td>
<td width="17%"><input type="text" class="form-control" id="usr"></td>
<td width="7%"> <button type="submit" class="btn ">SEARCH</button></td>
<td width="45%"> </td>
</tr>
</table>
</div>
<div style="padding-top:5px;">
<table width="100%" class="" id="">
<tr>
<td style="text-align:right;">Room Type :</td>
<td>
<select id="roomtypeAddmroom" name="roomtypeAddmroom" class="span3 " tabindex="1" data-placeholder="Choose a Category" onchange="roomTypesPARENTIDneed(this);">
<option value="">Select</option>
<s:iterator value="roomTypeList" status="rowstatus">
<option value="<s:property value='lookup_id'/>"><s:property value='dtl_name'/></option>
</s:iterator>
</select> </td>
<td> </td>
<td style="text-align:right;"> </td>
</tr>
<tr>
<td width="35%" style="text-align:right;">UD Room Id :</td>
<td width="20%" style="text-align:left;"><input id="udefineAddmroom" name="udefineAddmroom" type="text" class="form-control" ></td>
<td width="9%" style="text-align:center;"> </td>
<td width="36%" style="text-align:right;"> </td>
</tr>
<tr >
<td style="text-align:right;">Room Name : </td>
<td><input id="rnameAddmroom" name="rnameAddmroom" type="text" class="form-control" ></td>
<td> </td>
<td style="text-align:right;"> </td>
</tr>
<tr >
<td style="text-align:right;">Parent Id :</td>
<td id="roomTypesPARENTIDneed_div">
<select id="parentidAddmroom" name="parentidAddmroom" class="span3 " tabindex="1" data-placeholder="Choose a Category">
<option value="">Select</option>
</select> </td>
<td> </td>
<td style="text-align:right;"> </td>
</tr>
<tr>
<td style="text-align:right;">Size :</td>
<td><input id="sizeAddmroom" name="sizeAddmroom" type="text" class="form-control" ></td>
<td> </td>
<td> </td>
</tr>
<tr >
<td style="text-align:right;">Capacity : </td>
<td><input id="capacityAddmroom" name="capacityAddmroom" type="text" class="form-control" ></td>
<td> </td>
<td> </td>
</tr>
<tr >
<td style="text-align:right;">Device : </td>
<td><input id="deviceAddmroom" name="deviceAddmroom" type="text" class="form-control" ></td>
<td> </td>
<td> </td>
</tr>
<tr >
<td style="text-align:right;">Room Image </td>
<td colspan="3">
<input id="userImage" name="userImage" class="" type="file" > </td>
</tr>
<tr >
<td style="text-align:right;">Colour :</td>
<td><input id="colorAddmroom" name="colorAddmroom" type="text" class="form-control"></td>
<td> </td>
<td> </td>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
<!--a href="#" onclick="appCanPOPFunction();">second POPUP</i></a-->
</div>
</div>
<!-- END EXAMPLE TABLE widget-->
<!-- END PAGE CONTENT-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<!-- <button type="submit" class="btn btn-primary" >Save changes</button> -->
<button type="submit" class="btn btn-primary" >Save changes</button>
</div>
</form>
2/ script load by jquery :
function insertRoomTypeModalClose(){ //Start INSERT Meeting room Modal and Close
// alert("insert query : Room Type");
var kname="joya";
/* var udefineAddmroom = $("#udefineAddmroom").val();
var rnameAddmroom = $("#rnameAddmroom").val();
var pid1 = document.getElementById('parentidAddmroom');
var parentidAddmroom = pid1.options[pid1.selectedIndex].value;
var rt1 = document.getElementById('roomtypeAddmroom');
var roomtypeAddmroom = rt1.options[rt1.selectedIndex].value;
var sizeAddmroom = $("#sizeAddmroom").val();
var capacityAddmroom = $("#capacityAddmroom").val();
var deviceAddmroom = $("#deviceAddmroom").val();
var ajaxURL = "insertMeetingRoomCloseRI.do?udefineAddmroom="+udefineAddmroom+"&rnameAddmroom="+rnameAddmroom+"&parentidAddmroom="+parentidAddmroom+"&roomtypeAddmroom="+roomtypeAddmroom+"&sizeAddmroom="+sizeAddmroom+"&capacityAddmroom="+capacityAddmroom+"&deviceAddmroom="+deviceAddmroom+"&userImage=userImage";
$.ajax({
async:false,
url : ajaxURL,
success : function(result) {
$("#Kcontent_page").html(result);
},
complete:function(){
dataTableInitializeMeetingRoomGP();
$('#ARGSCCModal').modal('hide');
}
}); */
$('#myForm').submit(function(event){
//alert("Img");
//disable the default form submission
event.preventDefault();
//grab all form data
var formData = new FormData($(this)[0]);
$.ajax({
url: "insertMeetingRoomCloseMra.do?kname="+kname,
type: "POST",
cache: false,
processData: false,
contentType: false,
data: formData,
success: function (res) {
$("#Kcontent_page").html(res);
},
complete:function(){
dataTableInitializeMeetingRoomGP();
$('#ARGSCCModal').modal('hide');
} ,
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus+' : '+ errorThrown);
}
});
});
}
struts.xml :
<action name="*Mra" class="action.MeetingRoomAction" method="{1}">
<result name="insertMeetingRoomClose">ManageOrSetupPage/meetingRoom.jsp</result>
</action>
MeetingRoomAction.java :
public class MeetingRoomAction extends ActionSupport implements ServletRequestAware{
public String insertMeetingRoomClose(){
MeetingRoomSQL meetingRoomSQL = new MeetingRoomSQL();
System.out.println("Meeting Room info and image save");
try {
String filePath = servletRequest.getRealPath("/");
System.out.println("Server path:" + filePath);
File fileToCreate = new File(filePath, this.userImageFileName);
FileUtils.copyFile(this.userImage, fileToCreate);
filePath += userImageFileName;
File image = new File(filePath);
System.out.println(image);
FileInputStream fis = new FileInputStream(image);
meetingRoomSQL.insertMeetingRoomCloseData(udefineAddmroom,rnameAddmroom,parentidAddmroom,roomtypeAddmroom,sizeAddmroom,capacityAddmroom,deviceAddmroom,image,fis);
// meetingRoomSQL.insertMeetingRoomCloseData(udefineAddmroom,rnameAddmroom,parentidAddmroom,roomtypeAddmroom,sizeAddmroom,capacityAddmroom,deviceAddmroom,null,null);
} catch (Exception e) { //catch (IOException e)
e.printStackTrace();
}
meetingRoomList = meetingRoomSQL.selectMeetingRoomData();
return "insertMeetingRoomClose";
}
//FROM KYAMC iMage iNsert
private File userImage;
private String userImageContentType;
private String userImageFileName;
private HttpServletRequest servletRequest;
@Override
public void setServletRequest(HttpServletRequest servletRequest) {
this.servletRequest = servletRequest;
}
}
1.jsp page :
<form id="myForm" action="javascript:insertRoomTypeModalClose();" class="form-horizontal" method="post" enctype="multipart/form-data">
<div class="modal-body">
<!-- START PAGE CONTENT-->
<!-- BEGIN EXAMPLE TABLE widget-->
<div class="widget red">
<div class="widget-title">
<!--h4><i class="icon-reorder"></i> Data Table</h4-->
<!--span class="tools">
<a href="javascript:;" class="icon-chevron-down"></a>
<a href="javascript:;" class="icon-remove"></a>
</span-->
</div>
<div class="widget-body">
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="31%" style="text-align:right;font-family:Arial;font-size:12px;font-weight:bold;color:#000;">Search : </td>
<td width="17%"><input type="text" class="form-control" id="usr"></td>
<td width="7%"> <button type="submit" class="btn ">SEARCH</button></td>
<td width="45%"> </td>
</tr>
</table>
</div>
<div style="padding-top:5px;">
<table width="100%" class="" id="">
<tr>
<td style="text-align:right;">Room Type :</td>
<td>
<select id="roomtypeAddmroom" name="roomtypeAddmroom" class="span3 " tabindex="1" data-placeholder="Choose a Category" onchange="roomTypesPARENTIDneed(this);">
<option value="">Select</option>
<s:iterator value="roomTypeList" status="rowstatus">
<option value="<s:property value='lookup_id'/>"><s:property value='dtl_name'/></option>
</s:iterator>
</select> </td>
<td> </td>
<td style="text-align:right;"> </td>
</tr>
<tr>
<td width="35%" style="text-align:right;">UD Room Id :</td>
<td width="20%" style="text-align:left;"><input id="udefineAddmroom" name="udefineAddmroom" type="text" class="form-control" ></td>
<td width="9%" style="text-align:center;"> </td>
<td width="36%" style="text-align:right;"> </td>
</tr>
<tr >
<td style="text-align:right;">Room Name : </td>
<td><input id="rnameAddmroom" name="rnameAddmroom" type="text" class="form-control" ></td>
<td> </td>
<td style="text-align:right;"> </td>
</tr>
<tr >
<td style="text-align:right;">Parent Id :</td>
<td id="roomTypesPARENTIDneed_div">
<select id="parentidAddmroom" name="parentidAddmroom" class="span3 " tabindex="1" data-placeholder="Choose a Category">
<option value="">Select</option>
</select> </td>
<td> </td>
<td style="text-align:right;"> </td>
</tr>
<tr>
<td style="text-align:right;">Size :</td>
<td><input id="sizeAddmroom" name="sizeAddmroom" type="text" class="form-control" ></td>
<td> </td>
<td> </td>
</tr>
<tr >
<td style="text-align:right;">Capacity : </td>
<td><input id="capacityAddmroom" name="capacityAddmroom" type="text" class="form-control" ></td>
<td> </td>
<td> </td>
</tr>
<tr >
<td style="text-align:right;">Device : </td>
<td><input id="deviceAddmroom" name="deviceAddmroom" type="text" class="form-control" ></td>
<td> </td>
<td> </td>
</tr>
<tr >
<td style="text-align:right;">Room Image </td>
<td colspan="3">
<input id="userImage" name="userImage" class="" type="file" > </td>
</tr>
<tr >
<td style="text-align:right;">Colour :</td>
<td><input id="colorAddmroom" name="colorAddmroom" type="text" class="form-control"></td>
<td> </td>
<td> </td>
</tr>
<tr >
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</div>
<!--a href="#" onclick="appCanPOPFunction();">second POPUP</i></a-->
</div>
</div>
<!-- END EXAMPLE TABLE widget-->
<!-- END PAGE CONTENT-->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<!-- <button type="submit" class="btn btn-primary" >Save changes</button> -->
<button type="submit" class="btn btn-primary" >Save changes</button>
</div>
</form>
2/ script load by jquery :
function insertRoomTypeModalClose(){ //Start INSERT Meeting room Modal and Close
// alert("insert query : Room Type");
var kname="joya";
/* var udefineAddmroom = $("#udefineAddmroom").val();
var rnameAddmroom = $("#rnameAddmroom").val();
var pid1 = document.getElementById('parentidAddmroom');
var parentidAddmroom = pid1.options[pid1.selectedIndex].value;
var rt1 = document.getElementById('roomtypeAddmroom');
var roomtypeAddmroom = rt1.options[rt1.selectedIndex].value;
var sizeAddmroom = $("#sizeAddmroom").val();
var capacityAddmroom = $("#capacityAddmroom").val();
var deviceAddmroom = $("#deviceAddmroom").val();
var ajaxURL = "insertMeetingRoomCloseRI.do?udefineAddmroom="+udefineAddmroom+"&rnameAddmroom="+rnameAddmroom+"&parentidAddmroom="+parentidAddmroom+"&roomtypeAddmroom="+roomtypeAddmroom+"&sizeAddmroom="+sizeAddmroom+"&capacityAddmroom="+capacityAddmroom+"&deviceAddmroom="+deviceAddmroom+"&userImage=userImage";
$.ajax({
async:false,
url : ajaxURL,
success : function(result) {
$("#Kcontent_page").html(result);
},
complete:function(){
dataTableInitializeMeetingRoomGP();
$('#ARGSCCModal').modal('hide');
}
}); */
$('#myForm').submit(function(event){
//alert("Img");
//disable the default form submission
event.preventDefault();
//grab all form data
var formData = new FormData($(this)[0]);
$.ajax({
url: "insertMeetingRoomCloseMra.do?kname="+kname,
type: "POST",
cache: false,
processData: false,
contentType: false,
data: formData,
success: function (res) {
$("#Kcontent_page").html(res);
},
complete:function(){
dataTableInitializeMeetingRoomGP();
$('#ARGSCCModal').modal('hide');
} ,
error: function(jqXHR, textStatus, errorThrown) {
alert(textStatus+' : '+ errorThrown);
}
});
});
}
struts.xml :
<action name="*Mra" class="action.MeetingRoomAction" method="{1}">
<result name="insertMeetingRoomClose">ManageOrSetupPage/meetingRoom.jsp</result>
</action>
MeetingRoomAction.java :
public class MeetingRoomAction extends ActionSupport implements ServletRequestAware{
public String insertMeetingRoomClose(){
MeetingRoomSQL meetingRoomSQL = new MeetingRoomSQL();
System.out.println("Meeting Room info and image save");
try {
String filePath = servletRequest.getRealPath("/");
System.out.println("Server path:" + filePath);
File fileToCreate = new File(filePath, this.userImageFileName);
FileUtils.copyFile(this.userImage, fileToCreate);
filePath += userImageFileName;
File image = new File(filePath);
System.out.println(image);
FileInputStream fis = new FileInputStream(image);
meetingRoomSQL.insertMeetingRoomCloseData(udefineAddmroom,rnameAddmroom,parentidAddmroom,roomtypeAddmroom,sizeAddmroom,capacityAddmroom,deviceAddmroom,image,fis);
// meetingRoomSQL.insertMeetingRoomCloseData(udefineAddmroom,rnameAddmroom,parentidAddmroom,roomtypeAddmroom,sizeAddmroom,capacityAddmroom,deviceAddmroom,null,null);
} catch (Exception e) { //catch (IOException e)
e.printStackTrace();
}
meetingRoomList = meetingRoomSQL.selectMeetingRoomData();
return "insertMeetingRoomClose";
}
//FROM KYAMC iMage iNsert
private File userImage;
private String userImageContentType;
private String userImageFileName;
private HttpServletRequest servletRequest;
@Override
public void setServletRequest(HttpServletRequest servletRequest) {
this.servletRequest = servletRequest;
}
}
No comments:
Post a Comment