马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
Java的桌面程序开发在java程序员里通常叫swing开发,主要用的swing包里的类开发的,也就是通常说的c/s架构开发js|天生html<%@pagecontentType="text/html;charset=gb2312"%>
<%@pageimport="java.util.*"%>
<%@pageimport="java.sql.*"%>
<%@pageimport="java.io.*"%>
<%@pageimport="org.apache.commons.fileupload.*"%>
<%@pageimport="java.text.*"%>
<%@pageimport="javax.servlet.*,javax.servlet.http.*"%>
<jsp:useBeanid="conn"scope="page"class="DBLink.DBSQL"/>
<jsp:useBeanid="ReadTemplates"scope="page"class="ball.news.ReadTemplates"/>
<jsp:useBeanid="WriteHtml"scope="page"class="ball.news.WriteHtml"/>
<jsp:useBeanid="ReplaceAll"scope="page"class="ball.news.ReplaceAll"/>
<%
//request.setCharacterEncoding("gb2312");
try{
Stringdir=request.getRealPath(".");
DiskFileUploadfu=newDiskFileUpload();
fu.setSizeMax(4194304);//设置文件巨细.这里文件只能上传4M之内的
fu.setSizeThreshold(4096);//设置缓冲巨细.
fu.setRepositoryPath(dir+"/ball/news/images");//设置一时目次.
ListfileItems=fu.parseRequest(request);//剖析哀求,前往一个汇合.
Iteratori=fileItems.iterator();
Stringfieldvalue="";
Stringff="";
Stringpicname="false";
Objecttt="";
Vectorv=newVector();
while(i.hasNext())
{
FileItemfi=(FileItem)i.next();
if(fi.isFormField())//这是用来断定是不是为文件属性,
{
StringfieldName=fi.getFieldName();//这里获得表单名
fieldvalue=fi.getString();//这里获得表单值
v.addElement(fieldvalue);
}
else//这里入手下手外理文件
{
FilefullFile=newFile(fi.getName());
ff=fullFile.getName();
Stringrr="";
java.util.Datedate2=newjava.util.Date();
SimpleDateFormatformatter=newSimpleDateFormat("yyyyMMddHHmmss");//获得工夫
Stringstr2=formatter.format(date2);
StringTokenizerst=newStringTokenizer(ff,".");
if(st.hasMoreTokens()){
Stringtest12=st.nextToken();
rr=st.nextToken();
//System.out.println(rr);
}
if(rr.equals("")&&!rr.equals("gif")&&!rr.equals("jpg")&&!rr.equals("jpeg"))
{
picname="false";
}
else
{
picname=str2+"."+rr;//以工夫为图片称号
FilesavedFile=newFile(getServletContext().getRealPath("/ball/news/images/"),picname);
fi.write(savedFile);//上传到服务器
}
//System.out.println("picname------------------------"+picname);
}
//System.out.println("v------------------------"+v);
}
String[]flag={"<temp_title>","<temp_date>","<temp_author>","<temp_content>","<str_Temp>","<temp_picture>"};
//将数据写进到数据库
Objectnewtype1=v.elementAt(0);
Stringt=newtype1.toString();
intnewtype=Integer.parseInt(t);
Objectrowid1=v.elementAt(1);
Stringrowid=rowid1.toString();
Objecttitle1=v.elementAt(2);
Stringtitle=title1.toString();
Objectcontent1=v.elementAt(3);
Stringcontent=content1.toString();
//System.out.println(down);
java.util.Datedate=newjava.util.Date();
Stringstrdate=date.toLocaleString();
java.util.DateStrDate1=newjava.util.Date();
StringStrDate=StrDate1.toLocaleString();//旧事公布工夫
//Stringnewtype="0";
conn.openDB();
Stringsql="selecttop5*fromb_newswherenewtype="+newtype+"orderbyiddesc";
StringstrTemp="<tr><td>相干旧事</td></tr>";
ResultSetrs=conn.executeQuery(sql);
while(rs.next())
{
Stringt2=rs.getString(2);
Stringt4=rs.getString(4);
strTemp+="<tr><td>";
strTemp+="<ahref=../../../"+t4+">";
strTemp+=t2;
strTemp+="</a>";
}
strTemp+="</td></tr>";
rs.close();
//读取模板
StringfilePath="";
filePath=request.getRealPath("all
ewspnews.template");
StringtemplateContent=null;
try{
templateContent=ReadTemplates.getTlpContent(filePath);
System.out.println(templateContent);
}
catch(Exceptione)
{
System.out.println("errortotemplate!");
}
//交换模板中的内容
//System.out.println("picname--------------------------------"+picname);
templateContent=ReplaceAll.replace(templateContent,flag[0],title);
templateContent=ReplaceAll.replace(templateContent,flag[1],StrDate);
//templateContent=ReplaceAll.replace(templateContent,flag[2],editer);
templateContent=ReplaceAll.replace(templateContent,flag[3],content);
templateContent=ReplaceAll.replace(templateContent,flag[4],strTemp);
templateContent=ReplaceAll.replace(templateContent,flag[5],picname);
//依据工夫得文件名与路径名
Calendarcalendar=Calendar.getInstance();
StringfileName=String.valueOf(calendar.getTimeInMillis())+".html";
StringpathName=request.getRealPath("ball/news")+""+calendar.get(Calendar.YEAR)+""+(calendar.get(Calendar.MONTH)+1)+""+calendar.get(Calendar.DAY_OF_MONTH)+"";
Stringurl=calendar.get(Calendar.YEAR)+"/"+(calendar.get(Calendar.MONTH)+1)+"/"+calendar.get(Calendar.DAY_OF_MONTH)+"/";
url+=fileName;
//System.out.println(url);
try{
WriteHtml.save(templateContent,pathName,fileName);
}catch(Exceptione){
System.out.println("errortohtml!-----------"+e.getMessage());
}
//写进数据库
StringsqlInsert=null;
if(!picname.equals("false")){
sqlInsert="insertintob_news(title,content,url,picture,newtype,addtime,rowid)values("+title+","+content+","+url+","+picname+","+newtype+",getdate(),"+rowid+")";
}
else
{
picname="images/"+picname;
sqlInsert="insertintob_news(title,content,url,newtype,addtime,rowid)values("+title+","+content+","+url+","+newtype+",getdate(),"+rowid+")";
}
//System.out.println("sqlinsert---------------"+sqlInsert);
conn.executeUpdate(sqlInsert);
}
catch(Exceptione)
{
System.out.println("uploaderror------------------"+e.getMessage());
}
%>
<%out.println("旧事天生html乐成了!");%>
没有那个大公司会傻了吧唧用.net开发大型项目,开发了,那等于自己一半的生命线被微软握着呢。而.net不行,限制在window系统,又是捆绑,鄙视微软之! |