这个是servlet的动作
package com.xinlab.blueapple.servlet.tool;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import org.apache.log4j.Logger;
import com.jspsmart.upload.File;
import com.jspsmart.upload.SmartUpload;
import com.xinlab.blueapple.XinDBUtil;
import com.xinlab.blueapple.ad.AdConfig;
import com.xinlab.blueapple.util.BAProperty;
import com.xinlab.blueapple.util.XinlabUtil;
public class ChanUpdate extends XinToolSecureServlet {
private ServletConfig config;
final public void init(ServletConfig config) throws ServletException {
this.config = config;
}
private static final Logger vulogger = Logger.getLogger(AdConfig.class);
@Override
protected void executePost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
executeGet(request, response);
}
@Override
protected void executeGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
SmartUpload mySmartUpload = new SmartUpload();
try {
mySmartUpload.initialize(config, request, response);
mySmartUpload.upload();
File upfile = mySmartUpload.getFiles().getFile(0);
String ext=upfile.getFileExt();
vulogger.info("ext====is========"+ext);
Calendar calendar = Calendar.getInstance();
String filename= String.valueOf(calendar.getTimeInMillis())+"."+ext;
vulogger.info("filename1=====is========="+filename);
String destpath = BAProperty.getProperty("datapath");
String phypath=BAProperty.getProperty("phypath");
String infopath=destpath+"/"+filename;
String infophypath=phypath+"/"+filename;
vulogger.info("infopath======is======="+infopath);
vulogger.info("infopath11111======is======="+infophypath);
upfile.saveAs(infophypath, mySmartUpload.SAVE_PHYSICAL);
String infoname=mySmartUpload.getRequest().getParameter("infoname");
String infopro=mySmartUpload.getRequest().getParameter("infopro");
String infobt1=mySmartUpload.getRequest().getParameter("infobt1");
String infobt2=mySmartUpload.getRequest().getParameter("infobt2");
String infosms=mySmartUpload.getRequest().getParameter("infosms");
String chanid=mySmartUpload.getRequest().getParameter("chan_id");
String pid=mySmartUpload.getRequest().getParameter("proid");
String type=mySmartUpload.getRequest().getParameter("type");
Enumeration<String> btname=mySmartUpload.getRequest().getParameterNames();
while(btname.hasMoreElements()){
String name=btname.nextElement();
if(name!=null&&!"".equals(name)){
if(name.equals("updateinfo")){
if(infobt1!=null&&!("".equals(infobt1))&&infobt2!=null&&!("".equals(infobt2))&&infosms!=null&&!("".equals(infosms)))
{
XinDBUtil.updateChanInfo(Integer.parseInt(chanid), infoname, infopro, infopath, infobt1, infobt2, infosms);
XinlabUtil.getChannlesByProductId(pid, true);
}
String [][]channel=XinDBUtil.selectChannInfo(chanid);
request.setAttribute("chaninfo", channel);
request.setAttribute("pid", pid);
request.setAttribute("type", type);
String url = "/tool/freemium_update.jsp";
request.getRequestDispatcher(url).forward(request, response);
break;
}
if(name.equals("insterinfo")){
if(infobt1!=null&&!("".equals(infobt1))&&infobt2!=null&&!("".equals(infobt2))&&infosms!=null&&!("".equals(infosms))){
XinDBUtil.addChanInfo(Integer.parseInt(pid.trim()), infoname, infopro, infopath, infobt1, infobt2, infosms);
XinlabUtil.getChannlesByProductId(pid, true);
}
request.setAttribute("pid", pid);
String page=request.getParameter("page") == null?"":request.getParameter("page");
String [] [] chann=XinDBUtil.getChannlByPrducts(pid);
request.setAttribute("chan", chann);
request.setAttribute("type", type);
String url = "/tool/freemium_tool.jsp";
request.getRequestDispatcher(url).forward(request, response);
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
前台页面
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ include file="/cm/taglib.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upsell Content Tool - Airtel Alerts</title>
<style>
/* CSS Document, Copyright 2008-09 Xinlab, Inc. All Rights Reserved. */
body,div,ul,li,h3,hr,form,fieldset,p{margin:0; padding:0; position:relative}
body{font-family:Verdana, Arial, Helvetica, sans-serif; font-size:68.75%} img{border:none; vertical-align:middle}
hr{border:none 0; border-top:1px solid; width:100%; height:1px; margin:.25em 0} h3,h6{font-size:110%}
p{line-height:1.175em; padding:.125em 0 .125em 0} ul,li{list-style:none} li{vertical-align:middle; white-space:nowrap}
form#search fieldset{display:block; width:95%; background-repeat:repeat-x; text-align:left; padding:2px; height:auto; border:none 0}
form#search fieldset#plain{background-image:none; width:100%; border:none 0}
form#search input,form#gen textarea{width:100%; border:1px solid}
form#search #button,form#gen #button,form.g .button{margin:0.3em; padding-top:0.1em; width:auto; background-repeat:repeat-x; border:1px solid}
form#gen input,form.g input{border:1px solid; margin-bottom:3px; vertical-align:middle} form#gen fieldset,form.g fieldset{border:none 0}
form#gen fieldset#plain input,form.g fieldset.plain input{border:none 0; margin-bottom:3px; vertical-align:middle}
form#gen fieldset#plain label,form.g fieldset.plain label{vertical-align:middle}
.f_l{float:left} .clear{clear:both} .align_c{text-align:center} .flush_r{text-align:right}
.bold,.message{font-weight:bold} .red,.red a:link{color:#FF0000;} .small{font-size:91%} .nowrap{white-space:nowrap}
.width8pct{margin:0 2%} .thumb{margin:3px} .playthumb{margin:3px 1px 3px 0} .blk{color:#000} .blk a:link,.blk a:visited{color:#264DCC}
#wrapper,#header{width:100%} #popular{vertical-align:bottom; padding:0; margin-left:3px; display:inline;}
#themes{height:20px; width:100%; clear:both; text-align:center; padding-top:4px; margin:2px 0 -4px 0}
#content,#footer{display:block; clear:both; padding:3px} #footer{margin:.5em 0 .25em 0; border-top:1px solid}
#title,#searchtitle{display:block; width:100%; background:repeat-x center; padding:2px; margin-bottom:.25em; border:none 0}
.ad{display:block;width:100%;text-align:center;font-weight:bold;border:2px solid #FF6633;background:#FF6633}
.ad a:link,.ad a:visited{color:#FFF}
/* CSS Document, Copyright 2008-09 Xinlab, Inc. All Rights Reserved. */
body{background-color:#FFF; color:#000} hr{color:#97AEF7; border-top-color:#97AEF7}
a:link,a:visited{color:#264DCC} a:hover,a:active{color:#A0BF7A}
.bevel{background-image:url(images/bevel.gif); border-top:1px solid #B5BDBB; border-bottom:1px solid #848C89}
form#search input,form#gen input,form#search textarea,form#gen textarea,form.g input{border-top-color:#264DCC; border-bottom-color:#6D8CF1; border-left-color:#264DCC; border-right-color:#6D8CF1}
form#search #button,form#gen #button,form.g .button{background-image:url(images/button.gif); border-bottom-color:#264DCC; border-left-color:#6D8CF1; border-top-color:#6D8CF1; border-right-color:#264DCC; color:#000}
#header,#themes,#content{background-color:#FFF} #topcolor,#footer{background-color:#ECF1F2} #footer{border-top-color:#97AEF7}
#title{background-image:url(images/bevel.gif); border-top:1px solid #B5BDBB; border-bottom:1px solid #848C89}
#searchtitle{background-color:#D8DEDC; border-top:1px solid #B5BDBB; border-bottom:1px solid #97AEF7}
.light{color:#999999;} .color{color:#264DCC;} .message{color:#FF6633;}
</style>
<script language="javascript">
function checkform(form){
if(form.infobt1.value==""||form.infobt2.value==""||form.infosms.value==""){
alert("You fill out the incomplete information please fill!");
form.name.focus();
return false;
}
}
</script>
<script type="text/javascript">
var picPath;
var image;
var box;
function LoadImage(ele, show_pos_obj) {
picPath = GetImgPath(ele);
if (picPath != "" && picPath != null) {
image = new Image();
image.src = picPath;
box = GetObj(show_pos_obj);
box.innerHTML = "<span style='color:gray;font-size:11px'>Loading...</span>";
setTimeout(ImgView, 1000);
} else {
return false;
}
}
function ImgView() {
if (image.width == 0 || image.height == 0) {
settimeout(ImgView, 1000);
} else {
if (box != null) {
var imgWidth = (image.width >= box.offsetWidth) ? box.offsetWidth : image.width;
var imgHeight = (image.height >= box.offsetHeight) ? box.offsetHeight : image.height;
var alt = "picture size :" + image.width + " * " + image.height;
box.innerHTML = "<img width='" + imgWidth + "' height='" + imgHeight + "' id='apic' src='" + picPath + "' οnlοad='DrawImage(this," + box.offsetWidth + "," + box.offsetHeight + ")' title=" + alt + " />";
}
}
}
function GetImgPath(obj) {
if (ValidateImgUrl(obj)) {
if (window.navigator.userAgent.indexOf("MSIE") >= 1) {
obj.select();
return document.selection.createRange().text;
}
else if (window.navigator.userAgent.indexOf("Firefox") >= 1) {
if (obj.files) {
return obj.files.item(0).getAsDataURL();
}
return obj.value;
}
return obj.value;
}
}
function ValidateImgUrl(obj) {
var url = GetObj(obj).value;
var filename = url.substring(url.lastIndexOf(".") + 1).toLowerCase();
if (filename != "jpg" && filename != "gif" && filename != "png" && filename != "bmp" && filename != "jpeg") {
alert("Picture format is incorrect, please choose the following format image upload jpg|gif|png|bmp"); return false;
}
if (url.length > 0) {
//return document.getElementById(id).value;
return true;
}
else { return false; }
}
function GetObj(id) {
return "string" == typeof id ? document.getElementById(id) : id;
}
var flag = false;
function DrawImage(ImgD, iwidth, iheight) {
var image = new Image();
image.src = ImgD.src;
if (image.width > 0 && image.height > 0) {
flag = true;
if (image.width / image.height >= iwidth / iheight) {
if (image.width > iwidth) {
ImgD.width = iwidth;
ImgD.height = (image.height * iwidth) / image.width;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
} else {
if (image.height > iheight) {
ImgD.height = iheight;
ImgD.width = (image.width * iheight) / image.height;
} else {
ImgD.width = image.width;
ImgD.height = image.height;
}
}
}
}
</script>
</head>
<body class="thumb">
<c:if test="${type!=null&&type!=''&&type=='tata'}">
<h3>Upsell Content Tool - Tatadocomo Alerts</h3>
</p>
<img src="../im/tatadocomo_upsell.gif" alt="tatadocomo" />
</c:if>
<c:if test="${type!=null&&type!=''&&type=='vodafone'}">
<h3>Upsell Content Tool - Vodafone Alerts</h3>
</p>
<img src="../im/vodafone_upsell.gif" alt="Vodafone" />
</c:if>
<c:if test="${type!=null&&type!=''&&type=='airtel'}">
<h3>Upsell Content Tool - Airtel Alerts</h3>
</p>
<img src="../im/airtel_upsell.gif" alt="Airtel" />
</c:if>
</p>
<br />
<form action="/tool/chanlupdate" method="post" enctype="multipart/form-data" οnsubmit="return checkform(this);">
<p>Channel Name: <input type="text" name="infoname" class="bold" size="40" id="chtitle" /></p>
<p>Promo Message / Price Point: <input type="text" size="40" id="chpromo" name="infopro" /></p>
<p>Channel Thumbnail: <input type="file" size="78" name="imageFile" οnchange='LoadImage(this,"box")'/></p>
<p>
<div id='box' style="width: 5px; height:5px"></div>
</p>
<p>Z value for button 1 ('Try It Now!'): <input type="text" name="infobt1" "/></p>
<p>Z value for button 2 ('No, thanks'): <input type="text" name="infobt2" "/></p>
<p>SMS URL: <input type="text" size="100" id="url" name="infosms" "/></p>
<input type="hidden" name="proid" value="${pid}" />
<input type="hidden" name="type" value="${type}" />
<p><input type="submit" class="button" name="insterinfo" value="submit"/></p>
</form>
<p><a href="/tool/free?pid=${pid}&type=${type}&c=1"><< Back to Channel List</a></p>
<p><a href="/tool/pfc"><< Back to Products List</a></p>
</body>
</html>