上传图片和音频到Server,再转存到DB

jsp页面

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<link rel="stylesheet" href="<c:url value='/plugin/ztree-v3.5.14/css/zTreeStyle/zTreeStyle.css'/>" type="text/css">
<script type="text/javascript" src="<c:url value='/plugin/ztree-v3.5.14/js/jquery.ztree.core-3.5.js'/>"></script>
<script type="text/javascript" src="<c:url value='/plugin/ztree-v3.5.14/js/jquery.ztree.excheck-3.5.js'/>"></script>
<script type="text/javascript" src="<c:url value='/plugin/ztree-v3.5.14/js/jquery.ztree.exedit-3.5.js'/>"></script>
<script language="javascript" type="text/javascript" src="<c:url value='/plugin/artDialog4.1.7/jquery.artDialog.js?skin=simple'/>"></script>
<script language="javascript" type="text/javascript" src="<c:url value='/plugin/artDialog4.1.7/plugins/iframeTools.js'/>"></script>
<script language= javascript  type= text/javascript  src="<c:url value='/default/scripts/jquery.form.js'/>" ></script>
<style>
<!--
input[type=text],select,textarea {width:300px;
}.mouse_pointer{cursor:pointer;}label.align_top {vertical-align: top;}label.align_mid {vertical-align: middle;}textarea {margin:0;padding:0;height:50px;}#editCourse_table {border: transparent;border-collapse: collapse;font-family: Arial,Helvetica,sans-serif;margin-top: 10px;}.editCourse_table td{/*background-color: #EFEFEF;*/border: transparent;padding: 5px 15px 5px 5px;vertical-align: middle;width:65%;}.editCourse_table td:first-child{text-align: right;width:20%;}.editCourse_table td:last-child {text-align:left;width:12px;}.notNullStar {vertical-align: sub;}.hidden {display: none;}
-->
</style><script>var saved;//值改变函数function valueChanged(elem){saved = false;}function reDisplay( wordDicObj ){$("input[name='wordDictionaryVo.word']").val(wordDicObj.word);$("input[name='wordDictionaryVo.abbreviative']").each(function(){$(this).removeAttr("checked");});if( wordDicObj.abbreviative == true ){$("input[name='wordDictionaryVo.abbreviative'][value='true']").attr("checked", true);}else{$("input[name='wordDictionaryVo.abbreviative'][value='false']").attr("checked", true);}//释义if( wordDicObj.wordExplain != null && wordDicObj.wordExplain != "" ){$("textarea[name='wordDictionaryVo.wordExplain']").val(wordDicObj.wordExplain);}if( wordDicObj.simpleExplain != null && wordDicObj.simpleExplain != "" ){$("textarea[name='wordDictionaryVo.simpleExplain']").val(wordDicObj.simpleExplain);}$("#wordImage").attr("src", "<c:url value='/worddictionary/getImageById.action?id='/>" + wordDicObj.id);if( wordDicObj.ukPhoneticSymbol != null && wordDicObj.ukPhoneticSymbol != "" ){$("input[name='wordDictionaryVo.ukPhoneticSymbol']").val(wordDicObj.ukPhoneticSymbol);}if( wordDicObj.ukPhoneSplit != null && wordDicObj.ukPhoneSplit != "" ){$("input[name='wordDictionaryVo.ukPhoneSplit']").val(wordDicObj.ukPhoneSplit);}if( wordDicObj.ukWordSplit != null && wordDicObj.ukWordSplit != "" ){$("input[name='wordDictionaryVo.ukWordSplit']").val(wordDicObj.ukWordSplit);}if( wordDicObj.ukAudioExist != null && wordDicObj.ukAudioExist == true ){$("#ukspeaker").attr("audioUrl","<c:url value='/worddictionary/getAudioByIdAndCountry.action?id='/>" + wordDicObj.id + "&countryType=uk");$("#ukspeaker").show();}else{$("#ukspeaker").attr("audioUrl","");$("#ukspeaker").hide();}if( wordDicObj.usPhoneticSymbol != null && wordDicObj.usPhoneticSymbol != "" ){$("input[name='wordDictionaryVo.usPhoneticSymbol']").val(wordDicObj.usPhoneticSymbol);}if( wordDicObj.usPhoneSplit != null && wordDicObj.usPhoneSplit != "" ){$("input[name='wordDictionaryVo.usPhoneSplit']").val(wordDicObj.usPhoneSplit);}if( wordDicObj.usWordSplit != null && wordDicObj.usWordSplit != "" ){$("input[name='wordDictionaryVo.usWordSplit']").val(wordDicObj.usWordSplit);}if( wordDicObj.usAudioExist != null && wordDicObj.usAudioExist == true ){$("#usspeaker").attr("audioUrl","<c:url value='/worddictionary/getAudioByIdAndCountry.action?id='/>" + wordDicObj.id + "&countryType=us");$("#usspeaker").show();}else{$("#usspeaker").attr("audioUrl","");$("#usspeaker").hide();}}function clearDisplay(){$("input[name='wordDictionaryVo.abbreviative']").each(function(){$(this).removeAttr("checked");});$("input[name='wordDictionaryVo.abbreviative'][value='false']").attr("checked", true);$("textarea[name='wordDictionaryVo.wordExplain']").val("");$("textarea[name='wordDictionaryVo.simpleExplain']").val("");$("#wordImage").attr("src", "<c:url value='/worddictionary/getImageById.action?id='/>");$("input[name='wordDictionaryVo.ukPhoneticSymbol']").val("");$("input[name='wordDictionaryVo.ukPhoneSplit']").val("");$("input[name='wordDictionaryVo.ukWordSplit']").val("");$("#ukspeaker").attr("audioUrl","");$("#ukspeaker").hide();$("input[name='wordDictionaryVo.usPhoneticSymbol']").val("");$("input[name='wordDictionaryVo.usPhoneSplit']").val("");$("input[name='wordDictionaryVo.usWordSplit']").val("");$("#usspeaker").attr("audioUrl","");$("#usspeaker").hide();}$(function(){//radio输入改变事件$("input[type=radio]").change(function(){valueChanged(this);});$("input[type=text],textarea").bind("input propertychange",function(){valueChanged(this);});$("#word").keydown(function( evt ){if( evt.keyCode == 13 ){$("#queryButton").trigger("click");}});//单词查询Button$("#queryButton").click(function(){if($("#wordForm").validate().form()){var word = $.trim($("#word").val());$.ajax({url: "<s:url value='/worddictionary/getWordDictionaryByWord.action'/>",type: "post",async:true,data:{word:word},dataType: "json",contentType:"application/x-www-form-urlencoded; charset=UTF-8" ,   //success: function( rtnValue ){if(rtnValue== null ){clearDisplay();art.tips("单词或词组不存在,赶紧添加吧!",2);}else{clearDisplay();reDisplay( rtnValue );}},error: function(reqObj, strError, strObj){}});}});$.validator.addMethod("validChar", function(value, element, params){value = $.trim(value);if (/^[\w|\s|\-|']*$/.test(value)) {return true;}return false;},"单词或词组包含非法字符" );$("#wordForm").validate({//显示错误信息用的标签类型errorElement: "em",//验证规则rules: {"wordDictionaryVo.word":{required: true,maxlength:256,validChar: true}},messages: {"wordDictionaryVo.word":{required:"请输入单词或词组",maxlength:"单词或词组总长度太长",checkBlank:"单词或词组不能为空串",validChar:"单词或词组包含非法字符"}}});//保存$("#saveButton").click(function(){if(!$("#wordForm").validate().form()){var errorMessage = "";$("em.error").each(function(){errorMessage += $(this).text() + "<br/>";});art.tips(errorMessage,2.5);return;}if(saved){art.tips("已成功保存或无更改,无需再次保存",2.5);return;}$("#wordForm").ajaxSubmit({type:"post",dataType:"json",success: function(response) {if(response.message.saveSuccess){art.tips("保存成功!",1.5);saved = true;}else{art.tips("保存失败,"+response.message.errorMsg,2.5);}},error:function(response){art.tips("保存失败,网络错误",2.5);}});});//上传图片$("#uploadImage").click(function(evt){evt.preventDefault();var val = $(this).attr("name");art.dialog.data('name', val);art.dialog.open('<c:url value="/worddictionary/uploadImageDialog.action"/>',{id: 'iframedialogUpload',title: '',lock: true,width:400,drag:false,height:150,init: function () {var iframe = this.iframe.contentWindow; //获取子页面对象var top = art.dialog.top;// 获取父页面对象}},false);});//上传音频$("#uploadUKAudio,#uploadUSAudio").click(function(evt){evt.preventDefault();var val = $(this).attr("name");art.dialog.data('name', val);art.dialog.open('<c:url value="/worddictionary/uploadAudioDialog.action"/>',{id: 'iframedialogUpload',title: '',lock: true,width:400,drag:false,height:150,init: function () {var iframe = this.iframe.contentWindow; //获取子页面对象var top = art.dialog.top;// 获取父页面对象}},false);});$(".speaker").click(function(){var audioUrl = $(this).attr("audioUrl");thisMovie("wordDictionary_mp3Player").playAudio(audioUrl);});});function changeImage(name,imageName){$("#"+name).attr("src","<s:url value='/temp/images/'/>"+imageName);$("#"+name +"_hidden").val(imageName);saved = false;
}function changeAudio(name, audioName){var audioUrl = "<c:url value='/worddictionary/getAudioByFileName.action?audioServerFileName='/>" + audioName;$("#"+name).attr("audioUrl", audioUrl);$("#"+name).show();$("#"+name +"_hidden").val(audioName);saved = false;
}function thisMovie(movieName) {if (navigator.appName.indexOf("Microsoft") != -1) {return window[movieName];}else {return document[movieName];}
}</script><!-- 隐藏的ActionScript播放器类  -->
<!--  
<object style="width: 1px; height: 1px;position: absolute; top:0px; left:0px;" type="application/x-shockwave-flash" data="<c:url value='/flash/NetStreamAudioPlayerAS.swf?onLoadCompleted=onPlayerCompleted'/>" name="wordDictionaryAudioPlayer" id="wordDictionaryAudioPlayer" ><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="<c:url value='/flash/NetStreamAudioPlayerAS.swf?onLoadCompleted=onPlayerCompleted'/>" /><param name="quality" value="high" /><param name="scale" value="noScale" /><param name="wmode" value="transparent" />
</object>
--><object style="width: 0px; height: 0px;" type="application/x-shockwave-flash" data="/flash/Mp3PlayerAS.swf" name="wordDictionary_mp3Player" id="wordDictionary_mp3Player" ><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="/flash/Mp3PlayerAS.swf" /><param name="visible" value="false" />
</object><span class="font-18">单词编辑</span>
<form action="<c:url value='/worddictionary/saveWordDictionary.action'/>" method="post" id="wordForm" name="wordForm"><div style="width:860px;"><table id="editCourse_table" class="editCourse_table"><!-- 编辑区,公有属性 --><tbody><tr><td><label><span class="font-red notNullStar">*</span>单词:</label></td><td><s:textfield id="word" name="wordDictionaryVo.word"/><input type="button" class="button" name="queryButton"  value="查询" id="queryButton"/></td></tr><tr><td><label>是否是缩写:</label></td><td><input type="radio" name="wordDictionaryVo.abbreviative" value="false" checked/>否<input type="radio" name="wordDictionaryVo.abbreviative" value="true"/>是</td></tr><tr><td><label>释义:</label></td><td><s:textarea id="wordExplain" cols="50" name="wordDictionaryVo.wordExplain" /></td></tr><tr><td><label>简单释义:</label></td><td><s:textarea id="simpleExplain" cols="50" name="wordDictionaryVo.simpleExplain" /></td></tr><tr><td><label for="iconImage" class="align_top">图片:</label></td><td><img id="wordImage" style="width:140px;height:210px;border: 1px black solid;" src="<c:url value='/worddictionary/getImageById.action?id='/>${wordDictionaryVo.id}"/><s:hidden id="wordImage_hidden" name="wordDictionaryVo.imageServerFileName" onpropertychange="valueChanged(this)"/><a href="#" id="uploadImage" name="wordImage">上传图片</a></td></tr><tr><td><label>英式音标:</label></td><td><s:textfield id="ukPhoneticSymbol" name="wordDictionaryVo.ukPhoneticSymbol"/></td></tr><tr><td><label>英式发音音标分解:</label></td><td><s:textfield id="ukPhoneSplit" name="wordDictionaryVo.ukPhoneSplit"/></td></tr><tr><td><label>英式发音单词分解:</label></td><td><s:textfield id="ukWordSplit" name="wordDictionaryVo.ukWordSplit"/></td></tr><tr><td><label>英式发音:</label></td><td><input id="ukspeaker" class="icon-button speaker" audioUrl="" audioType="mp3" type="button" style="display:none;"><s:hidden id="ukspeaker_hidden" name="wordDictionaryVo.ukAudioServerFileName"/><a href="#" id="uploadUKAudio" name="ukspeaker">上传音频</a></td></tr><tr><td><label>美式音标:</label></td><td><s:textfield id="usPhoneticSymbol" name="wordDictionaryVo.usPhoneticSymbol"/></td></tr><tr><td><label>美式发音音标分解:</label></td><td><s:textfield id="usPhoneSplit" name="wordDictionaryVo.usPhoneSplit"/></td></tr><tr><td><label>美式发音单词分解:</label></td><td><s:textfield id="usWordSplit" name="wordDictionaryVo.usWordSplit"/></td></tr><tr><td><label>美式发音:</label></td><td><input id="usspeaker" class="icon-button speaker" audioUrl="" audioType="mp3" type="button" style="display:none;"><s:hidden id="usspeaker_hidden" name="wordDictionaryVo.usAudioServerFileName"/><a href="#" id="uploadUSAudio" name="usspeaker">上传音频</a></td></tr><tr><td></td><td><input type="button" class="button" name="saveButton"  value="保存" id="saveButton"/></td></tr></tbody></table></div></form>


Action XML配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN""http://struts.apache.org/dtds/struts-2.3.dtd">
<struts><package name="worddictionary" namespace="/worddictionary" extends="web-default"><!-- 到编辑单词主页--><action name="editWordDictionary" class="newWordDictionaryAction" method="editWordDictionary"><result name="success" type="tiles">editWordDictionary</result></action><!--根据id获取图片--><action name="getImageById" class="newWordDictionaryAction" method="getImageById"><result name="success" type="stream">  <param name="contentType">image/jpeg</param>  <param name="inputName">imageStream</param>  <param name="bufferSize">2048</param>  </result></action><!-- 根据单词或词组查询字典--><action name="getWordDictionaryByWord" class="newWordDictionaryAction" method="getWordDictionaryByWord"><result name="ajax" type="json"><param name="include">wordDictionaryVo</param></result></action><!-- 保存单词或词组到字典--><action name="saveWordDictionary" class="newWordDictionaryAction" method="saveWordDictionary"><result name="ajax" type="jsonmessage"><param name="message">message</param></result></action><!-- 上传图片到server弹出页面--><action name="uploadImageDialog" class="newWordDictionaryAction" method="uploadImageDialog"><result name="success" type="tiles">uploadImageDialog</result></action><!-- 保存单词或词组到字典--><action name="uploadImageByAjax" class="newWordDictionaryAction" method="uploadImageByAjax"><result name="ajax" type="jsonmessage"><param name="message">message</param></result></action><!-- 上传音频到server弹出页面--><action name="uploadAudioDialog" class="newWordDictionaryAction" method="uploadAudioDialog"><result name="success" type="tiles">uploadAudioDialog</result></action><!-- 上传音频--><action name="uploadAudioByAjax" class="newWordDictionaryAction" method="uploadAudioByAjax"><result name="ajax" type="jsonmessage"><param name="message">message</param></result></action><!-- 根据ID和国家获取音频--><action name="getAudioByIdAndCountry" class="newWordDictionaryAction" method="getAudioByIdAndCountry"><result name="success" type="stream">  <param name="contentType">audio/mp3</param>  <param name="inputName">audioStream</param>  <param name="bufferSize">2048</param>  </result></action><!-- 根据Server端的文件获取音频--><action name="getAudioByFileName" class="newWordDictionaryAction" method="getAudioByFileName"><result name="success" type="stream">  <param name="contentType">audio/mp3</param>  <param name="inputName">audioStream</param>  <param name="bufferSize">2048</param>  </result></action></package>
</struts>

Action类

package com.wisemen.hhb.module.worddictionary.action;import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import net.sf.json.JSONObject;
import org.apache.commons.io.FileUtils;
import com.wisemen.framework.server.action.BaseAction;
import com.wisemen.framework.server.exception.ActionException;
import com.wisemen.framework.util.StringUtils;
import com.wisemen.hhb.module.base.domain.WordDictionary;
import com.wisemen.hhb.module.base.vo.WordDictionaryVo;
import com.wisemen.hhb.module.worddictionary.biz.IWordDictionaryBiz;
import com.wisemen.hhb.module.worddictionary.util.WordDictionaryUtil;public class WordDictionaryAction extends BaseAction {private static final long serialVersionUID = 1L;private static final String DEFAULT_WORD_IMG_PATH="images/word_default.png";private static final String COUNTRY_UK = "uk";private static final String COUNTRY_US = "us";/*** 字典ID*/private String id;/*** 单词或词组*/private String word;/*** 字典Biz*/private IWordDictionaryBiz wordDictionaryBiz;/**rtmp服务器地址*/private String rtmpServerUrl;private ByteArrayInputStream imageStream;private ByteArrayInputStream audioStream;private Boolean useDefault = true;private WordDictionaryVo wordDictionaryVo;/**上传的图片文件*/private File file;/**文件名*/private String fileFileName;private String countryType;/*** 保存在Server端,音频的文件名*/private String audioServerFileName;//------------------------------get/set--------------------------public String getId() {return id;}public void setId(String id) {this.id = id;}public String getWord() {return word;}public void setWord(String word) {this.word = word;}public IWordDictionaryBiz getWordDictionaryBiz() {return wordDictionaryBiz;}public void setWordDictionaryBiz(IWordDictionaryBiz wordDictionaryBiz) {this.wordDictionaryBiz = wordDictionaryBiz;}public String getRtmpServerUrl() {return rtmpServerUrl;}public void setRtmpServerUrl(String rtmpServerUrl) {this.rtmpServerUrl = rtmpServerUrl;}public ByteArrayInputStream getImageStream() {return imageStream;}public void setImageStream(ByteArrayInputStream imageStream) {this.imageStream = imageStream;}public Boolean getUseDefault() {return useDefault;}public void setUseDefault(Boolean useDefault) {this.useDefault = useDefault;}public WordDictionaryVo getWordDictionaryVo() {return wordDictionaryVo;}public void setWordDictionaryVo(WordDictionaryVo wordDictionaryVo) {this.wordDictionaryVo = wordDictionaryVo;}public File getFile() {return file;}public void setFile(File file) {this.file = file;}public String getFileFileName() {return fileFileName;}public void setFileFileName(String fileFileName) {this.fileFileName = fileFileName;}public ByteArrayInputStream getAudioStream() {return audioStream;}public void setAudioStream(ByteArrayInputStream audioStream) {this.audioStream = audioStream;}public String getCountryType() {return countryType;}public void setCountryType(String countryType) {this.countryType = countryType;}public String getAudioServerFileName() {return audioServerFileName;}public void setAudioServerFileName(String audioServerFileName) {this.audioServerFileName = audioServerFileName;}//------------------------------get/set--------------------------/*** 进入单词编辑页*/public String editWordDictionary(){return SUCCESS;}/*** * <p>Description:字典的图片</p>* <p>Paramenter:</p>* <p>Return:</p>* <p>Exception:</p>* <p>Modified History: </p>*/public String getImageById(){boolean useDefaultImage = false;WordDictionary wordDictionary = null;logger.debug("id is "+id);//判断id是否为空if(StringUtils.isEmpty(id)){useDefaultImage = true;}else{wordDictionary = wordDictionaryBiz.getWordDictionaryById(id);}if(null == wordDictionary || null == wordDictionary.getImage() ){useDefaultImage = true;}if(useDefaultImage == true && useDefault == true){String path = request.getSession().getServletContext().getRealPath("/");String imagePath = path + DEFAULT_WORD_IMG_PATH;logger.debug("default word imagePath : " + imagePath);try {imageStream = new ByteArrayInputStream(FileUtils.readFileToByteArray(new File(imagePath)));} catch (IOException e) {e.printStackTrace();}} else {imageStream = new ByteArrayInputStream(wordDictionary.getImage());}return SUCCESS;}/*** * <p>Description:通过单词获取字典对象</p>* <p>Paramenter:</p>* <p>Return:</p>* <p>Exception:</p>* <p>Modified History: </p>*/public String getWordDictionaryByWord(){wordDictionaryVo = wordDictionaryBiz.getWordDictionaryByWord(word);return AJAX_RETURN_TYPE;}/*** * <p>Description:保存单词到字典</p>* <p>Paramenter:</p>* <p>Return:</p>* <p>Exception:</p>* <p>Modified History: </p>*/public String saveWordDictionary(){boolean saveSuccess = true;String errorMsg = "";try{String contextPath = request.getSession().getServletContext().getRealPath("/");wordDictionaryBiz.saveWordDictionary(wordDictionaryVo, contextPath);}catch( Exception e){logger.error( "保存词典错误:" + e.getMessage() );saveSuccess = false;errorMsg = e.getMessage() ;}Map<String, Object> jsonMap = new HashMap<String,Object>();jsonMap.put("saveSuccess", saveSuccess);jsonMap.put("errorMsg", errorMsg);message = JSONObject.fromObject(jsonMap).toString();return AJAX_RETURN_TYPE;}/*** * <p>Description:上传图片对话框</p>* <p>Paramenter:</p>* <p>Return:</p>* <p>Exception:</p>* <p>Modified History: </p>*/public String uploadImageDialog(){return SUCCESS;}/*** 异步上传图片文件到Server* @return* @author ShiJiapeng* @throws IOException */public String uploadImageByAjax() throws IOException{JSONObject json = new JSONObject();if(file == null || file.length() <= 0 || StringUtils.isEmpty(fileFileName)){json.put("success", false);json.put("message", "文件为空,请重新上传");message = json.toString();return AJAX_RETURN_TYPE;   }//获取文件后缀名String contextPath = request.getSession().getServletContext().getRealPath("/");String tempFileName = WordDictionaryUtil.createTempFileName(fileFileName);try{FileUtils.copyFile(file, new File(contextPath+ WordDictionaryUtil.TEMP_IMAGES_PATH+tempFileName));}catch( Exception e){logger.error( "上传图片错误:" + e.getMessage() );json.put("success", false);json.put("errorMsg", e.getMessage());message = json.toString();return AJAX_RETURN_TYPE;}json.put("success", true);json.put("imageName", tempFileName);message = json.toString();//防止IE下变成下载文件super.getServletResponse().setContentType("text/html");super.getServletResponse().getWriter().write(message);return null;}/*** * <p>Description:上传图片对话框</p>* <p>Paramenter:</p>* <p>Return:</p>* <p>Exception:</p>* <p>Modified History: </p>*/public String uploadAudioDialog(){return SUCCESS;}/*** * <p>Description:异步上传音频文件到Server</p>* <p>Paramenter:</p>* <p>Return:</p>* <p>Exception:</p>* <p>Modified History: </p>*/public String uploadAudioByAjax() throws IOException{JSONObject json = new JSONObject();if(file == null || file.length() <= 0 || StringUtils.isEmpty(fileFileName)){json.put("success", false);json.put("message", "文件为空,请重新上传");message = json.toString();return AJAX_RETURN_TYPE;   }//获取文件名String contextPath = request.getSession().getServletContext().getRealPath("/");String tempFileName = WordDictionaryUtil.createTempFileName(fileFileName);try{FileUtils.copyFile(file, new File(contextPath+ WordDictionaryUtil.TEMP_AUDIOS_PATH+tempFileName));}catch( Exception e){logger.error( "上传音频错误:" + e.getMessage() );json.put("success", false);json.put("errorMsg", e.getMessage());message = json.toString();return AJAX_RETURN_TYPE;}json.put("success", true);json.put("audioName", tempFileName);message = json.toString();logger.debug("message = " + message);//防止IE下变成下载文件super.getServletResponse().setContentType("text/html");super.getServletResponse().getWriter().write(message);return null;}/*** * <p>Description:根据ID和[英式]or[美式]返回音频</p>* <p>Paramenter:</p>* <p>Return:</p>* <p>Exception:</p>* <p>Modified History: </p>*/public String getAudioByIdAndCountry(){WordDictionary wordDictionary = null;if( StringUtils.isEmpty(id) || StringUtils.isEmpty(countryType) ){throw new ActionException("args error.");}wordDictionary = wordDictionaryBiz.getWordDictionaryById(id);if(null == wordDictionary){audioStream = new ByteArrayInputStream(new byte[0]);}else{byte[] audioByteArray = null;if( COUNTRY_UK.equals(countryType) ){audioByteArray = wordDictionary.getUkAudioFile();if( audioByteArray == null ){audioStream = new ByteArrayInputStream(new byte[0]);}else{audioStream = new ByteArrayInputStream(audioByteArray);}}else if( COUNTRY_US.equals(countryType) ){audioByteArray = wordDictionary.getUsAudioFile();if( audioByteArray == null ){audioStream = new ByteArrayInputStream(new byte[0]);}else{audioStream = new ByteArrayInputStream(audioByteArray);}}else{throw new ActionException("countryType=" + countryType +", error.");}}return SUCCESS;}/*** * <p>Description:根据Server端的音频文件,返回音频</p>* <p>Paramenter:</p>* <p>Return:</p>* <p>Exception:</p>* <p>Modified History: </p>*/public String getAudioByFileName(){if( StringUtils.isEmpty(audioServerFileName) ){throw new ActionException("args error.");}String contextPath = request.getSession().getServletContext().getRealPath("/");try {byte[] audioByteArray = FileUtils.readFileToByteArray( new File(contextPath+ WordDictionaryUtil.TEMP_AUDIOS_PATH +audioServerFileName) );audioStream = new ByteArrayInputStream(audioByteArray);} catch (IOException e) {audioStream = new ByteArrayInputStream(new byte[0]);}return SUCCESS;}
}

==========================================

图片上传弹出框jsp

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<script language="javascript" type="text/javascript" src="<c:url value='/plugin/artDialog4.1.7/jquery.artDialog.js?skin=simple'/>"></script>
<script language="javascript" type="text/javascript" src="<c:url value='/plugin/artDialog4.1.7/plugins/iframeTools.js'/>"></script>
<script language= javascript  type= text/javascript  src="<c:url value='/default/scripts/jquery.form.js'/>" ></script><script type="text/javascript">$(document).ready(function(){var win = art.dialog.opener;//来源页面if (art.dialog.data('name')) {name=art.dialog.data('name');// 获取由主页面传递过来的数据};//上传图像$("#uploadbtn").click(function(){var filePath = $('#file').val();if(filePath==null || filePath== ''){alert('请选择要上传的文件');return;}else{var tempArray = filePath.split('\\');var index = tempArray.length-1;if(tempArray[index].length > 300){alert('文件名过长,请修改后重新上传');return;}}$('#uploadbtn').attr("disabled",true);$('#uploadbtn').attr("value","上传中...");$('#uploadForm').ajaxSubmit({		dataType: "json",success: function (data){var imageName = data.imageName;if(imageName !=""){win.changeImage(name,imageName);art.dialog.close();}else{alert("上传失败,请重新上传");}$('#uploadbtn').attr("disabled",false);$('#uploadbtn').attr("value","上传");}});});$("#cancel").click(function(){art.dialog.close();});});</script>	<form id="uploadForm" action="<s:url value='/worddictionary/uploadImageByAjax.action'/>" method="post" enctype="multipart/form-data"><div style="text-align: center;margin-top: 20px;width: 100%;"><s:file name="file" size="20"  accept="image/*"  value="上传文件"></s:file>	</div><div style="text-align: center;margin-top: 20px;width: 100%;" ><span>支持上传jpg、gif、png、bmp格式的图片,大小不超过4M	</span></div>
</form>
<div style="width: 100%;text-align: right;margin-top: 20px;"><input id="uploadbtn"  type="button" class="button" value="上传" ><input id="cancel"  type="button" class="button" value="取消" style="margin-right:20px;">
</div>


音频上传弹出框jsp

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<script language="javascript" type="text/javascript" src="<c:url value='/plugin/artDialog4.1.7/jquery.artDialog.js?skin=simple'/>"></script>
<script language="javascript" type="text/javascript" src="<c:url value='/plugin/artDialog4.1.7/plugins/iframeTools.js'/>"></script>
<script language= javascript  type= text/javascript  src="<c:url value='/default/scripts/jquery.form.js'/>" ></script><script type="text/javascript">
//选择上传文件后回调
$.onFileSelected = function(file){var filePath = $(file).val();if(filePath==null || filePath== ''){alert('请选择要上传的音频文件');return;}/**var speaker = $(file).nextAll(".speaker");var info = $(file).next("span");info.text("上传中...");$(file).parents("form").ajaxSubmit({dataType: "json",success: function (data){if (data.success) {var audioId = data.audioId;var audioType = data.audioType;var audioName = data.audioName;info.text("");speaker.attr("audioId", audioId);speaker.attr("audioType", audioType);speaker.css("visibility", "visible");} else {info.text("上传失败,请重新上传");}}});**/
};$(document).ready(function(){var win = art.dialog.opener;//来源页面if (art.dialog.data('name')) {name=art.dialog.data('name');// 获取由主页面传递过来的数据};//上传图像$("#uploadbtn").click(function(){var filePath = $('#file').val();if(filePath==null || filePath== ''){alert('请选择要上传的文件');return;}else{var tempArray = filePath.split('\\');var index = tempArray.length-1;if(tempArray[index].length > 300){alert('文件名过长,请修改后重新上传');return;}}$('#uploadbtn').attr("disabled",true);$('#uploadbtn').attr("value","上传中...");$('#uploadForm').ajaxSubmit({		dataType: "json",success: function (data){var audioName = data.audioName;if(audioName !=""){win.changeAudio(name,audioName);art.dialog.close();}else{alert("上传失败,请重新上传");}$('#uploadbtn').attr("disabled",false);$('#uploadbtn').attr("value","上传");}});});$("#cancel").click(function(){art.dialog.close();});});</script>	<form id="uploadForm" action="<s:url value='/worddictionary/uploadAudioByAjax.action'/>" method="post" enctype="multipart/form-data"><div style="text-align: center;margin-top: 20px;width: 100%;"><input id="file" name="file" accept="audio/mp3" type="file" οnchange="$.onFileSelected(this)"></div><div style="text-align: center;margin-top: 20px;width: 100%;" ><span>支持上传mp3格式的音频,大小不超过4M	</span></div>
</form><div style="width: 100%;text-align: right;margin-top: 20px;"><input id="uploadbtn"  type="button" class="button" value="上传" ><input id="cancel"  type="button" class="button" value="取消" style="margin-right:20px;">
</div>





本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/497667.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

区分大小屏幕_第一个Python程序——在屏幕上输出文本

本节我将给大家介绍最简单、最常用的 Python 程序——在屏幕上输出一段文本&#xff0c;包括字符串和数字。Python 使用 print 函数在屏幕上输出一段文本&#xff0c;输出结束后会自动换行。在屏幕上输出字符串字符串就是多个字符的集合&#xff0c;由双引号" "或者单…

2018 年物联网发展五大趋势预测

来源&#xff1a;腾股创投作者 &#xff1a;Pramod Chandrayan物联网已经开始在所有行业的企业中走向主流。 到 2018 年底&#xff0c;物联网支出预计将增长 15&#xff05;&#xff0c;达到 7725 亿美元&#xff0c;毫无疑问&#xff0c;未来一年连接设备和企业物联网项目数量…

js中立即执行函数会预编译吗_JavaScript预编译过程

什么是预编译&#xff1f;当js代码执行时有三个步骤&#xff1a;1.语法分析&#xff0c;这个过程检查出基本的语法错误。2&#xff0c;预编译&#xff0c;为对象分配空间。3&#xff0c;解释执行&#xff0c;解释一行执行一行&#xff0c;一旦出错立即停止执行。预编译发生在代…

知识图谱火了,但你知道它的发展历史吗?|赠书5本

作者&#xff1a;尼克 编辑&#xff5c;Emily版式由AI前线整理知识图谱火了&#xff0c;但你知道它的发展历史吗&#xff1f;本文节选自《人工智能简史》第 3 章&#xff0c;从第一个专家系统 DENDRAL 到语义网再到谷歌的开源知识图谱&#xff0c;对知识图谱的发展历程进行了…

python使用selenium_如何在python中使用selenium的示例

最近基于selenium写了一个python小工具,记录下学习记录,自己运行的环境是Ubuntu 14.04.4, Python 2.7,Chromium 49.0,ChromeDriver 2.16selenium简介selenium提供了一个通用的接口,可模拟用户来操作浏览器,比如用于自动化测试等.selenium的核心是WebDriver,它提供了一组接口,这…

英特尔爆发史诗级芯片漏洞,Linux之父痛斥英特尔公司

来源&#xff1a;CEO来信概要&#xff1a;1月4日消息&#xff0c;英特尔处理器存在芯片级漏洞的消息仍在发酵&#xff0c;恐怕将会成为计算机行业发展史上最大的安全漏洞之一。1月4日消息&#xff0c;英特尔处理器存在芯片级漏洞的消息仍在发酵&#xff0c;恐怕将会成为计算机行…

曲线均匀分布_曲线篇:深刻理解B 样条曲线(下)

前两篇中讲解了贝塞尔曲线和B样条基础。FrancisZhao&#xff1a;曲线篇: 贝塞尔曲线​zhuanlan.zhihu.comFrancisZhao&#xff1a;曲线篇&#xff1a;深刻理解B 样条曲线&#xff08;上&#xff09;​zhuanlan.zhihu.com本文讲一下B样条的进阶clamped B样条由于我们常用的B样条…

JSON.parse()解析单引号错误的问题

1、当用JSON.parse()方法&#xff0c;解析从后台传来的json字符串&#xff0c;而且字符串中含有单引号(如Iam ....)&#xff0c;页面将出现如下异常 2、页面引起报错部分 3、解决办法&#xff1a;在后台将特殊字符转义 bookBlockVoListJSONString BaseStringUtils.getJsonFor…

python复杂非线性方程_非线性方程python入门——屠龙刀

感谢师兄提供的题图。(这图应该是p的&#xff0c;我找电视剧&#xff0c;没谢三哥这三个字。)早些年做科研的时候&#xff0c;其实就用倚天屠龙走天下&#xff0c;一个矩阵对角化&#xff0c;一个非线性方程求解。当时是研究的冷原子&#xff0c;算是比较新的方向&#xff0c;量…

Facebook人工智能实验室提出「全景分割」,实现实例分割和语义分割的统一

原文来源&#xff1a;arxiv作者&#xff1a;Alexander Kirillov、Kaiming He1、Ross Girshick、Carsten Rother、Piotr Dollar「雷克世界」编译&#xff1a;嗯~阿童木呀、KABUDA现如今&#xff0c;我们提出并研究了一种新的“全景分割”&#xff08;Panoramic segmentation&…

ajax工作中使用模板

<!-- 生成课件 --><action name"createCourseware" class"coursewareManagementAction" method"createCourseware"><result name"ajax" type"jsonmessage"><param name"message">message…

数学一年级应用题_一年级数学下册应用题大全(附带答案)

应用题可以说是小学数学中最为重要的内容&#xff0c;是培养学生数学思维及解题能力的重要途径&#xff0c;做好应用题掉小学生非常重要&#xff0c;职场达人网精选100道一年级数学下册应用题&#xff0c;并附带答案。1、原有29个球&#xff0c;借出8个&#xff0c;还剩多少个&…

art.dialog弹出框后再根据其内部iframe的大小调整大小

1、主页面&#xff0c;用来弹出弹出页面 //查看错误小练习$.exerciseClick function(rowId ){$.event.get().preventDefault();var tdScore $("#" rowId).find("[aria-describedbyhomeworkStudentListGrid_score]");if( parseInt(tdScore.html()) 100 …

lg空调代码大全解决_LG空调故障代码大全

LG空调故障代码大全LG空调故障代码&#xff1b;PS/PRNA系列&#xff1b;CO&#xff1b;室内进风热敏电阻故障。C1&#xff1b;室内盘管热敏电阻故障。C4&#xff0c;室外热敏电阻故障包括室外环温&#xff0c;室外盘管&#xff0c;压机回气。C5&#xff0c;室内&#xff0c;室外…

句子录音打分代码参考

1、页面名称:sentenceReadRecordDialogAnyone.jsp 2、页面效果 3、页面源码 <% page language"java" pageEncoding"UTF-8" contentType"text/html;charsetUTF-8"%> <% include file"/common/taglibs.jsp"%><script la…

工具用途_见微知著,小工具大用途!

为什么同一个饮品&#xff0c;店家做的尝起来如此美味。拿到配方后自己做的不是甜了就是酸了呢&#xff1f;相信很多朋友都有这种疑惑。但真相往往就会在不经意间被忽视&#xff0c;很多初学者并没有老师傅那样的熟练手感&#xff0c;可以做到信手拈来的程度。当没有那些量勺&a…

带暂停功能的音频播放代码参考

1、页面来源&#xff1a;sentenceExercise07.jsp 2、页面效果 3、源代码 <% page language"java" pageEncoding"UTF-8" contentType"text/html;charsetUTF-8"%> <% include file"/common/taglibs.jsp"%> <% include f…

Yann LeCun 怒喷 Sophia:这就是彻头彻尾的骗局

来源&#xff1a;雷锋网&#xff08;leiphone-sz&#xff09;作者&#xff1a;杨晓凡在各种机器学习方法火热、神经网络加速芯片和生成式模型火热、研究人员们常常为优秀论文拍案叫绝的 2017 年中&#xff0c;普通大众视野中的热门人工智能成果除了 AlphaGo&#xff0c;还有一件…

ad16自动布线设置规则_AD16快捷方式和常规设置

1.快捷方式:快速修改丝印位置。选中元件 按快捷键A然后按P。Ti &#xff1a;差分等长TR &#xff1a;蛇形走线MG &#xff1a;修改铜皮多根走线(选中要走的几根线 按快捷键TTM 几根可以同时走线。PM)调整元件坐标移动(选中元件 按一下M 选择通过X、Y移动选择。)shiftG&#xff…

麦肯锡报告:传统车企正面临出行的数字化颠覆

来源&#xff1a;车云未来的个人出行情景将迎来一个巨大转变&#xff0c;更加倾向于颠覆性科技和其创新商业模式。毫无疑问&#xff0c;汽车产业正在面临颠覆。消费者行为上的巨大变化正在改变汽车行业的现状&#xff0c;尤其是因为人们更加注重了所有的车内体验&#xff0c;而…