<学习文件>
//自动刷新列表分组
function refreshGroupList(contentGroupId){
if(contentGroupId == null) return;
$.ajax({
url:"<%=request.getContextPath()%>/admin/c!groupList.action",
type:"POST",
dateType:"json",
success:function(contentGroupList){
if(contentGroupList != null){
var length = contentGroupList.length;
//控件的选项长度等于结果集的长度
document.getElementById('groupId').options.length = length;
document.getElementById('groupId').options[0] = new Option('全部',0);
var j = 0;
for(var i=1;i<=length;i++){
document.getElementById('groupId').options[i] = new Option(contentGroupList[j].contentGroupName,contentGroupList[j].contentGroupId);
if(contentGroupId == contentGroupList[j].contentGroupId)
document.getElementById('groupId').options[i].selected = true;
j = j + 1;
}
}else{
$("#groupId").html("");
}
}
});
}
在页面尾部调用此方法
<script>refreshGroupList('<%=(String)request.getParameter("contentGroupId")%>');</script>
——————————————————————————————————————————————————————————
//自动刷新主页面
parent.frames[0].refreshPage(); // 子页面
function refreshPage(){
location.href = '<%=request.getContextPath()%>admin/c!getList.action; //父页面
}
------------------------------------------------------------------------------------------------------------------
// 自动关闭 页面
parent.ClosePop();
----------------------------------------------------------------------------------------------------------------
// 获取子页面的元素值 写到父页面去
parent.callBack(参数); 子页面
function callBack(contentText){
//alert(contentText);
$("#contentText").val(contentText); 父页面
}
-------------------------------------------------------------------------------------------------------------------
//读取文件内容
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(new FileInputStream(
account.getTemplateFile()), "GBK"));
StringBuilder builder2 = new StringBuilder();
char[] chars = new char[1024];
int length = 0;
while (0 < (length = reader.read(chars))) {
builder2.append(chars, 0, length);
}
--------------------------------------------------------------------------------------------------------------------
//inpue = "file" 上传文件
//上传文件
InputStream in = null;
OutputStream out = null;
try{
in = new FileInputStream(account.getTemplateFile());
HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);
//HttpServletResponse response = (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE);
String dir = request.getRealPath("/");
String fileName = System.currentTimeMillis() + ".xls";
File uploadFile = new File(dir + Constants.ACCOUNT_UPLOAD_PATH , fileName);
out = new FileOutputStream(uploadFile);
byte[] buffer = new byte[1024 * 1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
account.setTemplateFileName(dir + Constants.ACCOUNT_UPLOAD_PATH + fileName);
}catch(FileNotFoundException ex){
ex.printStackTrace();
}catch(IOException ex){
ex.printStackTrace();
}finally{
try{
in.close();
out.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
__________________________________________________________________________________________________________
//把文字转换成图片
public class LongTextUtil {
private BufferedImage image;
private FileOutputStream fos;
/**
* 输出流
*/
private BufferedOutputStream bos;
/**
* 文本分隔符
*/
private String SPLIT_FLAG = ";;";
/**
* 输入一段长文本,返回长文本转换图片后生成后的地址 <br/>
* translateLongText <br/>
* TODO 适用条件: <br/>
* TODO 执行流程: <br/>
* TODO 使用方法: <br/>
* TODO 注意事项: <br/>
*
* @param longText 长文本内容<br/>
* @param outputFilePath 生成的图片全路径<br/>
* @throws <br/>
* @since Ver1.0 <br/>
* <br/>
*/
public String translateLongText(String longText,String outputFilePath) {
//文本长度
int textLength = longText.length();
//每行字符数
int lineLength = 30;
//总行数
int totalLine = (int) Math.ceil((double)textLength/(double)lineLength);
// 图片的宽度
int imageWidth = 375;
//图片的高度(总行数*每行高度)
int imageHeight = totalLine * 16;
image = new BufferedImage(imageWidth, imageHeight,BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.setFont(new Font("宋体",Font.PLAIN,12));//字体/风格/字号
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, imageWidth, imageHeight);
graphics.setColor(Color.BLACK);
//graphics.drawString(text, 50, 75);
//将长文本转换为多行
StringBuffer sb = new StringBuffer();
int step = 0;
for(int i = 0;i<totalLine;i++){
sb.append(longText.substring(step,
(step + lineLength)>textLength?textLength:(step + lineLength)));
sb.append(SPLIT_FLAG);
if(step + lineLength < textLength)
step = step + lineLength;
else
step = textLength;
}
if(sb.length() > 1) sb.delete(sb.length() - 2, sb.length());
//System.out.println(sb.toString());
String[] textArray = sb.toString().split(SPLIT_FLAG);
int startColumn = 5;//输出文本的起始列
int startRow = 15;//输出文本的起始行
for(int i=0;i<textArray.length;i++){
graphics.drawString(textArray[i],startColumn,startRow);
startRow += 15;//75是行与行之间的间距
//System.out.println("(" + startColumn + "," + startRow + ") " + textArray[i]);
}
graphics.dispose();
createImage(outputFilePath);
return outputFilePath;
}
private void createImage(String fileLocation) {
try {
fos = new FileOutputStream(fileLocation);
bos = new BufferedOutputStream(fos);
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image);
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
fos.close();
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public void graphicsGeneration(String name, String id, String classname,
String imgurl) {
int imageWidth = 500;// 图片的宽度
int imageHeight = 400;// 图片的高度
image = new BufferedImage(imageWidth, imageHeight,BufferedImage.TYPE_INT_RGB);
Graphics graphics = image.getGraphics();
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 0, imageWidth, imageHeight);
graphics.setColor(Color.BLACK);
graphics.drawString("姓名 : " + name, 50, 75);
graphics.drawString("学号 : " + id, 50, 150);
graphics.drawString("班级 : " + classname, 50, 225);
// ImageIcon imageIcon = new ImageIcon(imgurl);
// graphics.drawImage(imageIcon.getImage(), 230, 0, null);
// 改成这样:
BufferedImage bimg = null;
try {
bimg = javax.imageio.ImageIO.read(new java.io.File(imgurl));
} catch (Exception e) {
}
if (bimg != null)
graphics.drawImage(bimg, 230, 0, null);
graphics.dispose();
createImage("c:\\hehe.jpg");
}
public static void main(String[] args) {
//LongTextUtil.translateLongText("一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本一段长文本");
LongTextUtil util = new LongTextUtil();
try {
util.translateLongText("百度开发者中心是为开发者集中提供开发、部署、提交、推广、统计分析、换量、变现等一站式网络技术服务的服务平台,旨在开放、合作、共赢的理念上与开发者携手共建健康良性的互联网行业生态系统。百度开发者中心提供Web应用、移动客户端、合作网站三种类型应用的相关技术服务,开发者可以通过创建应用时接受对应类型应用的服务协议获得创建该类型应用的资格,从而获得相应的技术服务支持。百度开发者中心是为开发者集中提供开发、部署、提交、推广、统计分析、换量、变现等一站式网络技术服务的服务平台,旨在开放、合作、共赢的理念上与开发者携手共建健康良性的互联网行业生态系统。百度开发者中心提供Web应用、移动客户端、合作网站三种类型应用的相关技术服务,开发者可以通过创建应用时接受对应类型应用的服务协议获得创建该类型应用的资格,从而获得相应的技术服务支持。百度开发者中心是为开发者集中提供开发、部署、提交、推广、统计分析、换量、变现等一站式网络技术服务的服务平台,旨在开放、合作、共赢的理念上与开发者携手共建健康良性的互联网行业生态系统。百度开发者中心提供Web应用、移动客户端、合作网站三种类型应用的相关技术服务,开发者可以通过创建应用时接受对应类型应用的服务协议获得创建该类型应用的资格,从而获得相应的技术服务支持。",
"D:\\dev\\workspace\\ermoo.cn\\web\\upload\\long\\"
+ System.currentTimeMillis() + ".jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
}
_________________________________________________________________________________________________________________________
//用链接表示 input =“file”
<tr> <span style="display:none;">
<form id="form_txt" action="<%=request.getContextPath()%>/account!readText.action" method="post" enctype="multipart/form-data">
<input type="file" name="account.templateFile" id="input_file" onchange="$('#form_txt').submit();"/>
</form>
</span> <a href="#" onclick="$('#input_file').click();" style="font-size:14px">从文本文件读取</a> </tr>
<tr>
_______________________________________________________________________________________________________________________
用js 控制页面 让页面的内容变成一个子字面加载 包含分页知识
function loadData(pageIndex){
var mediaTypeId = $('#mediaTypeId').val();
var siteId = $('#siteId').val();
var groupId = $('#groupId').val();
var maintainUserName = $('#maintainUserName').val();
var maintainState = $('#maintainState').val();
var maintainTime = $('#maintainTime').val();
//加载列表数据
var gridAction="<%=request.getContextPath()%>/account!list.action";
//获取当前页数
if(!pageIndex)
pageIndex='${pageBean.currentPage}';
//读取数据
showGridLoading();
//执行查询
$("#divGrid").load(gridAction,{
actionName:gridAction,
container:"divGrid",
currentPage:pageIndex,
mediaTypeId:mediaTypeId,
siteId:siteId,
groupId:groupId,
maintainUserName:maintainUserName,
maintainState:maintainState,
maintainTime:maintainTime
},
function(){
hideGridLoading();//隐藏ajax层
}
);
}
________________________________________________________________________________
点击全选 全取消
//全选/取消
function selectAll(flag){
var array = document.getElementsByName('select');
var num = array.length;
//alert(num);
document.getElementById('id').value = '' ;
for( var i=0;i<num;i++){
if(flag == 0){
array[i].checked = true;
document.getElementById('id').value += array[i].value + ","
}else{
array[i].checked = false;
}
}
}
//已读/未读
function selectReadAll(flag){
var array = document.getElementsByName('select');
var num = array.length;
//alert(num);
document.getElementById('id').value = '' ;
for( var i=0;i<num;i++){
array[i].checked = false;
if($(array[i]).attr("readState") == flag){//接收私信人是否已阅读标志位(1:未阅读 2:已阅读)
array[i].checked = true;
str= document.getElementById('id').value += array[i].value + ","
}
}
}
//删除事件
function deleteAll(){
var idStr = $('#id').val();
if(idStr ==""){
alert("请选择预删除的信件");
}else{
$.ajax({
url:"<%=request.getContextPath()%>/p!deleteAll.action",
type:"POST",
dateType:"json",
data:{"idStr":idStr},
success : function(result){
if(result == 2){
alert("删除成功");
location.href="<%=request.getContextPath()%>p!perList.action" ;
}else if(result == 1){
alert("网络异常");
}
}
});
}
}
————————————————————————————————————————————————————————
上传照片
/**
* 普通上传
* <br/>
* addOneAlbum <br/>
* TODO 适用条件: <br/>
* TODO 执行流程: <br/>
* TODO 使用方法: <br/>
* TODO 注意事项: <br/>
* @param <br/>
* @throws <br/>
* @since Ver1.0 <br/>
* <br/>
*/
@SuppressWarnings("deprecation")
public String addOneAlbum(){
ActionContext context = ActionContext.getContext();
//上传文件
InputStream in = null;
OutputStream out = null;
try{
in = new FileInputStream(album.getImgUrlFile());
HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);
String dir = request.getRealPath("/");
String fileName = System.currentTimeMillis() + ".jpg";
//分目录存放上传的文件
long l = System.currentTimeMillis();
String split = l/1000000000L+"/";
File uploadFile = new File(dir + Constants.USER_ALBUM_COVER_PATH + split);
if (!uploadFile.exists()) {
uploadFile.mkdirs();
}
out = new FileOutputStream(uploadFile + "/" + fileName);
byte[] buffer = new byte[1024 * 1024];
int length;
while ((length = in.read(buffer)) > 0) {
out.write(buffer, 0, length);
}
album.setUrl(Constants.USER_ALBUM_COVER_PATH + split + fileName);
//向页面上设置返回值
ActionContext.getContext().put("url", album.getUrl());
}catch(FileNotFoundException ex){
ex.printStackTrace();
}catch(IOException ex){
ex.printStackTrace();
}finally{
try{
in.close();
out.close();
}catch(IOException ex){
ex.printStackTrace();
}
}
if(StringUtil.isNotNull(album)){
setNumber(albumService.addOneAlbum(album));
//向页面上设置返回值
ActionContext.getContext().put("number", getNumber());
return "addOneAlbum";
}
return ERROR;
}
public String uploadImages(){
try {
uploadImage();
return "uploadImages";
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ERROR;
}
@SuppressWarnings("unused")
public void uploadImage() throws Exception{
//System.out.println("OK!");
if (Filedata == null || Filedata.size() == 0){
return;
}
for (int i = 0; i < Filedata.size(); ++i){
String fileName = FiledataFileName.get(i); // 文件真名
long length = Filedata.get(i).length(); // 文件的真实大小
long time = System.currentTimeMillis();
// 将上传的文件保存到服务器的硬盘上
InputStream is = new BufferedInputStream(new FileInputStream(Filedata.get(i)));
HttpServletRequest request = ServletActionContext.getRequest(); // 获得ServletRequest对象
//request.getRealPath("/")已不建议使用,改为this.getServletContext().getRealPath("/")
System.out.println("path:"+ServletActionContext.getServletContext().getRealPath("/"));
//File tempFile = new File(ServletActionContext.getServletContext().getRealPath("/uploadimages")+File.separator+fileName);
File tempFile = new File("E://upload/test"+File.separator+fileName);
FileUtils.forceMkdir(tempFile.getParentFile()); // 创建上传文件所在的父目录
OutputStream os = new BufferedOutputStream( new FileOutputStream(tempFile));
int len = 0;
byte[] buffer = new byte[500];
while (-1 != (len = is.read(buffer))){
os.write(buffer, 0, len);
}
is.close();
os.flush();
os.close();
}
}
___________________________________________________________________________________________________________
js 克隆html
var sourceNode = document.getElementById("callBack"); // 获得被克隆的节点对象
var clonedNode = sourceNode.cloneNode(true); // 克隆节点
// clonedNode.setAttribute("id", "div-" + i); // 修改一下id 值,避免id 重复
sourceNode.parentNode.appendChild(clonedNode); // 在父节点插入克隆的节点
_______________________________________________________________________________________
mysql
将查询出的数据导出到表格
SELECT fromUrl,title,url ,a FROM (
SELECT
'fromUrl' AS fromUrl,
'title' AS title ,
'url' AS url ,
'count(fromUrl)' AS a
UNION
SELECT fromUrl,title,url,count(fromUrl) FROM ermoo_app_monitoring_result where title like '%祖山%' GROUP BY fromUrl order by title desc
) TT
INTO OUTFILE 'd:/test1.xls';
——————————————————————————————————————————————
mysql
返回多行记录时候的拼接
SELECT GROUP_CONCAT(DISTINCT xxx SEPARATOR ',') FROM 表
" SELECT r.id,r.userId,r.mediaTypeId,r.siteId,r.monitoringId,r.competeId,r.analystsUserId,r.createTime," +
"r.url,r.title,r.monitoringResultId,r.dimensions ,r.sourceName,r.replyRate,r.clickRate ,"+
" r.writer,r.industryId ,r.dimensionNames,r.source,r.dictiIdDimension,r.dictiIdPattern,r.dictiIdNature," +
" (select GROUP_CONCAT(CONCAT(orientation,'.',remark) SEPARATOR ',')" +
" FROM ermoo_app_monitoring_orientations WHERE r.id=reportId )as orientations " +
" FROM ermoo_app_monitoring_report_result r WHERE r.id IS NOT NULL" ;
_____________________________________________________________________________________________________