<%
String fileName = (String) session.getId();
String fileExt = "";
String groupName="";//集团名称
List list=new ArrayList();//集团手机号码
String upload = request.getParameter("upload");
String userList = "";
String msg = "请选择要导入文件(Txt或Excel)";
if(upload==null){
%>
<jsp:useBean id="myUpload" scope="request" class="com.jspsmart.upload.SmartUpload" />
<%
String dir = request.getRealPath("/");
// out.println(dir);
myUpload.initialize(pageContext);
myUpload.upload();
if (!myUpload.getFiles().getFile(0).isMissing()){
com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(0);
fileExt = myFile.getFileExt();
if(!fileExt.equalsIgnoreCase("txt")&&!fileExt.equalsIgnoreCase("xls")){
msg = "文件类型错误,请选择Txt或Excel文件!";
}
myFile.saveAs(dir+java.io.File.separatorChar+fileName+"."+fileExt); if (fileExt.equalsIgnoreCase("txt")){
InputStream is = null;
java.io.Reader reader = null;
java.io.BufferedReader bufReader = null;
try
{
is = new FileInputStream(dir+java.io.File.separatorChar+fileName+"."+fileExt);
reader = new java.io.InputStreamReader(is);
bufReader = new java.io.BufferedReader(reader);
String sCurrentLine = "";
while ((sCurrentLine = bufReader.readLine()) != null)
{
userList += sCurrentLine+";";
}
msg = "导入成功";
}
catch (Exception e)
{
out.println("文件类型错误");
}
finally{
is.close();
reader.close();
bufReader.close();
}
}
if (fileExt.equalsIgnoreCase("xls")){
InputStream is = null;
jxl.Workbook rwb = null;
try
{
is = new FileInputStream(dir+java.io.File.separatorChar+fileName+"."+fileExt);
rwb = Workbook.getWorkbook(is);
Sheet rs = rwb.getSheet(0);
int iRow = rs.getRows();
for(int i=1; i<iRow ; i++){
//Cell cell = rs.getCell(0, i);
groupName=rs.getCell(0,1).getContents();
list.add(rs.getCell(1,i).getContents());
System.out.println(rs.getCell(0,i).getContents()+" = "+rs.getCell(1,i).getContents());
//userList += cell.getContents()+";";
}
request.setAttribute("list",list);
msg = "导入成功";
}
catch (Exception e)
{
out.println("文件类型错误");
}
finally{
is.close();
rwb.close();
}
}
try{
java.io.File delFile= new java.io.File(dir+java.io.File.separatorChar+fileName+"."+fileExt);
delFile.delete();
}
catch(Exception e){
e.printStackTrace();
}
}
}//if
%>
<html>
<head>
<title>导入黑名单</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<style>
body, td{
font-size:12px;
background-color:#F0F0F0;
font-family:Verdana;
margin:0px
}
.bttn{background: #D6E7EF;border-bottom: 1px solid #104A7B;border-right: 1px solid #104A7B;
border-left: 1px solid #AFC4D5;border-top:1px solid #AFC4D5;color:#000066;
height:19px;text-decoration:none;cursor: hand;font-size:9pt}a{color:#6699cc;text-decoration:none}
</style>
<script language="JavaScript">
function submiting(){
form1.button1.value = "正在导入...";
form1.button1.disabled = true;
document.form1.action="lei.jsp";
form1.submit();
}
function openhu(){
var guoupName=document.getElementById("guoupName").value;
var mobilephones=document.getElementById("mobilephones").value;
if(guoupName=="" || mobilephones==null ){alert("请导入该集团的名称及手机号!");return false;}
else{if(confirm("您确定要为该集团开户吗?"))
document.form1.action="query.jsp?guoupName="+guoupName+"&mobilephones="+mobilephones;
form1.submit();
}
}</script>
</head><body leftmargin="3" topmargin="3" >
<table width="75%" cellpadding="5">
<form name="form1" action="" enctype="multipart/form-data" method="post">
<tr>
<td><font color="red"><h3><%=msg %></h3></font></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="file" name="file" >
</td>
</tr>
<tr>
<td align="right" colspan="1">
<input name="button1" type="button" class="bttn" id="button1" onclick="submiting();" value=" 导 入 ">
</td>
</tr>
<tr>
<td align="right"><b>集团名称</b></td>
<td>
<% if(groupName=="" || groupName==null){%>
<%groupName="";}%>
<input type="text" name="guoupName" value="<%=groupName %>">
</td>
</tr>
<tr>
<td align="right"><b>手机号码</b></td>
<td><input type="text" name="mobilephones" value="<%=list %>"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="开 户" onclick=" return openhu();"></td>
</tr>奇怪为什么movilephones的文本框里有"[]",怎么样才能让它里面的空白的.我想了好多办法还是没有搞定希望高手帮下忙 解决问题马上给分!
String fileName = (String) session.getId();
String fileExt = "";
String groupName="";//集团名称
List list=new ArrayList();//集团手机号码
String upload = request.getParameter("upload");
String userList = "";
String msg = "请选择要导入文件(Txt或Excel)";
if(upload==null){
%>
<jsp:useBean id="myUpload" scope="request" class="com.jspsmart.upload.SmartUpload" />
<%
String dir = request.getRealPath("/");
// out.println(dir);
myUpload.initialize(pageContext);
myUpload.upload();
if (!myUpload.getFiles().getFile(0).isMissing()){
com.jspsmart.upload.File myFile = myUpload.getFiles().getFile(0);
fileExt = myFile.getFileExt();
if(!fileExt.equalsIgnoreCase("txt")&&!fileExt.equalsIgnoreCase("xls")){
msg = "文件类型错误,请选择Txt或Excel文件!";
}
myFile.saveAs(dir+java.io.File.separatorChar+fileName+"."+fileExt); if (fileExt.equalsIgnoreCase("txt")){
InputStream is = null;
java.io.Reader reader = null;
java.io.BufferedReader bufReader = null;
try
{
is = new FileInputStream(dir+java.io.File.separatorChar+fileName+"."+fileExt);
reader = new java.io.InputStreamReader(is);
bufReader = new java.io.BufferedReader(reader);
String sCurrentLine = "";
while ((sCurrentLine = bufReader.readLine()) != null)
{
userList += sCurrentLine+";";
}
msg = "导入成功";
}
catch (Exception e)
{
out.println("文件类型错误");
}
finally{
is.close();
reader.close();
bufReader.close();
}
}
if (fileExt.equalsIgnoreCase("xls")){
InputStream is = null;
jxl.Workbook rwb = null;
try
{
is = new FileInputStream(dir+java.io.File.separatorChar+fileName+"."+fileExt);
rwb = Workbook.getWorkbook(is);
Sheet rs = rwb.getSheet(0);
int iRow = rs.getRows();
for(int i=1; i<iRow ; i++){
//Cell cell = rs.getCell(0, i);
groupName=rs.getCell(0,1).getContents();
list.add(rs.getCell(1,i).getContents());
System.out.println(rs.getCell(0,i).getContents()+" = "+rs.getCell(1,i).getContents());
//userList += cell.getContents()+";";
}
request.setAttribute("list",list);
msg = "导入成功";
}
catch (Exception e)
{
out.println("文件类型错误");
}
finally{
is.close();
rwb.close();
}
}
try{
java.io.File delFile= new java.io.File(dir+java.io.File.separatorChar+fileName+"."+fileExt);
delFile.delete();
}
catch(Exception e){
e.printStackTrace();
}
}
}//if
%>
<html>
<head>
<title>导入黑名单</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<style>
body, td{
font-size:12px;
background-color:#F0F0F0;
font-family:Verdana;
margin:0px
}
.bttn{background: #D6E7EF;border-bottom: 1px solid #104A7B;border-right: 1px solid #104A7B;
border-left: 1px solid #AFC4D5;border-top:1px solid #AFC4D5;color:#000066;
height:19px;text-decoration:none;cursor: hand;font-size:9pt}a{color:#6699cc;text-decoration:none}
</style>
<script language="JavaScript">
function submiting(){
form1.button1.value = "正在导入...";
form1.button1.disabled = true;
document.form1.action="lei.jsp";
form1.submit();
}
function openhu(){
var guoupName=document.getElementById("guoupName").value;
var mobilephones=document.getElementById("mobilephones").value;
if(guoupName=="" || mobilephones==null ){alert("请导入该集团的名称及手机号!");return false;}
else{if(confirm("您确定要为该集团开户吗?"))
document.form1.action="query.jsp?guoupName="+guoupName+"&mobilephones="+mobilephones;
form1.submit();
}
}</script>
</head><body leftmargin="3" topmargin="3" >
<table width="75%" cellpadding="5">
<form name="form1" action="" enctype="multipart/form-data" method="post">
<tr>
<td><font color="red"><h3><%=msg %></h3></font></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="file" name="file" >
</td>
</tr>
<tr>
<td align="right" colspan="1">
<input name="button1" type="button" class="bttn" id="button1" onclick="submiting();" value=" 导 入 ">
</td>
</tr>
<tr>
<td align="right"><b>集团名称</b></td>
<td>
<% if(groupName=="" || groupName==null){%>
<%groupName="";}%>
<input type="text" name="guoupName" value="<%=groupName %>">
</td>
</tr>
<tr>
<td align="right"><b>手机号码</b></td>
<td><input type="text" name="mobilephones" value="<%=list %>"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="开 户" onclick=" return openhu();"></td>
</tr>奇怪为什么movilephones的文本框里有"[]",怎么样才能让它里面的空白的.我想了好多办法还是没有搞定希望高手帮下忙 解决问题马上给分!
===
调用了list.toString()方法,按照这样的格式返回数据的:[data1,data2,...]
如果list为空当然就是[]了
public String toString() {
Iterator<E> i = iterator();
if (! i.hasNext())
return "[]"; StringBuilder sb = new StringBuilder();
sb.append('[');
for (;;) {
E e = i.next();
sb.append(e == this ? "(this Collection)" : e);
if (! i.hasNext())
return sb.append(']').toString();
sb.append(", ");
}
}
=====
你想让它是空白的直接value=""不就行了吗?
<input type="text" name="mobilephones" value="<%=list.size() == 0 ? "" : list.toString() %>">
<input type="text" name="mobilephones" value="<%=list.toString().substring(1, list.toString().length()-1)">
<input type="text" name="mobilephones" value="<%=list.toString().substring(1, list.toString().length()-1)%>">