基于javaweb+mysql的jsp+servlet在线旅游旅行综合服务平台(java+mysql+jsp+servlet)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)
前台用户+后台管理
基于javaweb+mysql的JSP+Servlet在线旅游旅行综合服务平台(java+mysql+jsp+servlet)
// #1157B7
buf.append(" ");
if (this.currentPage > 1) {
buf.append("<a href='").append(this.path).append("¤tPage=")
.append(currentPage - 1).append(parameter).append(
"' class='ls'>").append("上页")
.append("</a>");
} else {
buf.append("上页");
}
buf.append(" ");
int currentSegment = this.currentPage % segment == 0 ? this.currentPage
/ segment : this.currentPage / segment + 1;
/*for (int i = 1; i <= this.pageNumber; i++) {
if (this.currentPage == i)
buf.append("<font color='red'>").append(i).append("</font>");
else
buf.append("<a href='").append(this.path).append(
"¤tPage=").append(i).append(parameter).append(
"' class='ls'>[").append(i).append(
"]</a>");
}*/
buf.append(" ");
if (this.currentPage < this.pageNumber) {
buf.append("<a href='").append(this.path).append("¤tPage=")
.append(currentPage + 1).append(parameter).append(
"' class='ls'>").append("下页")
.append("</a>");
} else {
buf.append("下页");
}
buf.append(" ");
if (this.currentPage == this.pageNumber)
buf.append("末页 ");
else
buf.append("<a href='").append(this.path).append("¤tPage=")
.append(this.pageNumber).append(parameter).append(
"' class='ls'>").append("末页")
.append("</a></font> ");
//
// for (int i = 0; i < this.pageNumber; i++) {
// if (this.currentPage == i + 1) {
// buf.append("<font color=red>[" + (i + 1) + "]</font>").append(
// " ");
// } else {
}
}
}
}
sql = sql.substring(0, sql.length() - 1);
sql += " where id=" + request.getParameter("id");
System.out.println(sql);
Statement st1 = conn.createStatement();
st1.execute(sql);
st1.close();
rs.close();
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
String str = "";
if (!reflush)
str += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
str += "<script language=javascript>\n";
if (alert) {
str += "alert('操作成功');\n";
}
if (tzurl.equals("")) {
if (reflush) {
str += "parent.location=parent.location;\n";
} else {
str += "window.location=String(window.location).replace(new RegExp('f=f', 'g'), '');";
}
} else {
str += "location.href='" + tzurl + "';\n";
}
str += "</script>\n";
PrintWriter wrt = null;
try {
//request.get
wrt = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wrt.write(str);
}
return "";
}
public Connection getConn() {
try {
if (conn == null || conn.isClosed()) {
return i;
}
public void commOper(String sql) {
System.out.println(sql);
try {
Statement st = conn.createStatement();
st.execute(sql);
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void commOperSqls(ArrayList<String> sql) {
try {
conn.setAutoCommit(false);
for (int i = 0; i < sql.size(); i++) {
Statement st = conn.createStatement();
System.out.println(sql.get(i));
st.execute(sql.get(i));
st.close();
}
conn.commit();
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
} finally {
try {
conn.setAutoCommit(true);
} catch (SQLException e) {
e.printStackTrace();
}
}
}
if(FileUpload.isMultipartContent(requestContext)){
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100*1024*1024);
List items = new ArrayList();
items = upload.parseRequest(request);
FileItem fileItem = (FileItem) items.get(0);
if(fileItem.getName()!=null && fileItem.getSize()!=0)
{
if(fileItem.getName()!=null && fileItem.getSize()!=0){
File fullFile = new File(fileItem.getName());
filename = Info.generalFileName(fullFile.getName());
File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
try {
fileItem.write(newFile);
} catch (Exception e) {
e.printStackTrace();
}
}else{
}
}
}
go("/js/uploadimg2.jsp?filename="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploadimg3"))
{
try {
String filename="";
request.setCharacterEncoding("UTF-8");
RequestContext requestContext = new ServletRequestContext(request);
if(FileUpload.isMultipartContent(requestContext)){
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100*1024*1024);
List items = new ArrayList();
return jscode;
}
public static String getImgUpInfo5(int height)
{
String jscode = "";
jscode+="<img style=\"cursor: hand\" οnclick=\"uploadimg5()\" src=\"js/nopic.jpg\" id=txt5 height=\""+height+"\"/>";
jscode+="<input type=hidden name=\"filename5\" id=\"filename5\" value=\"\" />";
return jscode;
}
public static String fck(int height,String content)
{
String jscode = "<TEXTAREA name=\"content\" id=\"content\">"+content+"</TEXTAREA>";
jscode+="<script language=\"javascript\">";
jscode+="function fckinit()";
jscode+="{";
jscode+=" var of = new FCKeditor(\"content\");";
jscode+="of.BasePath=\"fckeditor/\";";
jscode+="of.Height = \""+height+"\";";
jscode+="of.ToolbarSet=\"Default\";";
jscode+="of.ReplaceTextarea();";
jscode+="}";
jscode+="fckinit();";
jscode+="</script>";
return jscode;
}
public synchronized static String subStr(String source,int length) {
if(source.length()>length)
{
source=source.substring(0,length)+"...";
}
return source;
}
public synchronized static String ensubStr(Object source,int length) {
String msource = Info.filterStrIgnoreCase(source.toString(), "<", ">");
if(msource.length()>length)
{
msource=msource.substring(0,length)+"...";
}
return msource;
}
try {
workbook = Workbook.getWorkbook(new File(request.getRealPath("/upfile/")+"/"+filename));
//通过Workbook的getSheet方法选择第一个工作簿(从0开始)
Sheet sheet = workbook.getSheet(0);
//通过Sheet方法的getCell方法选择位置为C2的单元格(两个参数都从0开始)
//int empty = 0;
for(int i=1;i<1000;i++)
{
Cell cell = null;
try{
String isql = "insert into "+tablename+"(";
for(String str:whzdstr.split("-"))
{
isql+=str+",";
}
isql = isql.substring(0,isql.length()-1);
isql+=")values(";
int j=0;
int empty = 1;
for(String str:whzdstr.split("-"))
{
cell = sheet.getCell(j,i);
isql+="'"+cell.getContents()+"',";
String content = cell.getContents()==null?"":cell.getContents();
if(!"".equals(content.trim()))
{
empty = 0;
}
j++;
}
if(empty==1)continue;
isql = isql.substring(0,isql.length()-1);
isql+=")";
dao.commOper(isql);
}catch (Exception e) {
continue;
}
public class Upload extends HttpServlet {
/**
* Constructor of the object.
*/
public Upload() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
String jscode = "";
jscode+="<font οnclick=\"uploaddoc3()\" src=\"js/nopic.jpg\" style='cursor:hand' id=filetxt3 >点击此处上传</font>";
jscode+=" <input type=text readonly style='border:0px' size=30 name=\"docname3\" id=\"docname3\" value=\"\" />";
return jscode;
}
public static String tform(HashMap map,String formname)
{
String jscode = "";
try{
jscode+="<script type=\"text/javascript\">\n";
jscode+="function getPvalue()\n";
jscode+="{\n";
Set set = map.entrySet();
Iterator it = set.iterator();
while(it.hasNext())
{
String pm=((Object)it.next()).toString();
String str1 = "";
String str2 = "";
String[] strs = pm.split("=");
str1 = strs[0];
if(strs.length==1)str2="";
if(strs.length==2)str2=strs[1];
str2 = str2.replaceAll("\r\n", "---");
// str2 = str2.replaceAll("\"", "'");
if(!str1.equals("content")){
jscode+=" if(document.getElementsByName(\""+str1+"\").length>1)\n";
jscode+=" {\n";
jscode+=" var radios = document.getElementsByName(\""+str1+"\");\n";
jscode+=" if(radios[0].type=='radio'){\n";
jscode+=" for(var i=0;i<radios.length;i++)\n";
jscode+=" {\n";
jscode+=" if(radios[i].value==\""+str2+"\")\n";
jscode+=" {\n";
jscode+=" radios[i].checked=\"checked\";\n";
jscode+=" }\n";
jscode+=" }\n";
jscode+=" }\n";
jscode+=" if(radios[0].type=='checkbox'){\n";
jscode+=" for(var i=0;i<radios.length;i++)\n";
jscode+=" {\n";
jscode+=" if(\""+str2+"\".indexOf(radios[i].value)>-1&&radios[i].id.indexOf('choosebox')==-1)\n";
}
/**
*
* @param 查询条件集合
* 如没有条件只是列表就不使用这个方法
*/
public void addParameter(List parameter) {
StringBuffer para = new StringBuffer("");
if (parameter != null && parameter.size() != 0) {
Iterator iterator = parameter.iterator();
while (iterator.hasNext()) {
para.append("&").append(iterator.next().toString());
}
}
this.parameter = para.toString();
}
/**
* 刷新分页路径
*
*/
protected void refreshUrl() {
StringBuffer buf = new StringBuffer();
buf.append("<font color='#1157B7'>共").append(count);
buf.append("条");
buf.append(" ");
buf.append("第").append(this.currentPage).append("/").append(
this.pageNumber).append("页");
buf.append(" ");
if (this.currentPage == 1)
buf.append("首页");
else
buf.append("<a href='").append(this.path).append("¤tPage=1")
.append(parameter)
.append("' class='ls'>").append("首页")
.append("</a>");
// #1157B7
buf.append(" ");
if (this.currentPage > 1) {
sql = sql.substring(0, sql.length() - 1) + ")";
System.out.println(sql);
this.commOper(sql);
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
String str = "";
if (!reflush)
str += "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> \n";
str += "<script language=javascript>\n";
if (alert) {
str += "alert('操作成功');\n";
}
if (tzurl.equals("")) {
if (reflush) {
str += "parent.location=parent.location;\n";
} else {
str += "window.location=String(window.location).replace(new RegExp('f=f', 'g'), '');";
}
} else {
str += "location.href='" + tzurl + "';\n";
}
str += "</script>";
PrintWriter wrt = null;
try {
wrt = response.getWriter();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wrt.write(str);
}
return "";
}
public void delete(HttpServletRequest request, String tablename) {
}
}
public String getCols(String table) {
String str = "";
Connection conn = this.getConn();
try {
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from " + table);
ResultSetMetaData rsmd = rs.getMetaData();
int i = rsmd.getColumnCount();
for (int j = 2; j <= i; j++) {
str += rsmd.getColumnName(j) + ",";
}
} catch (Exception e) {
e.printStackTrace();
}
str = str.substring(0, str.length() - 1);
return str;
}
public String update(HttpServletRequest request, HttpServletResponse response, String tablename, HashMap extmap, boolean alert, boolean reflush, String tzurl) {
if (request.getParameter("f") != null) {
Enumeration enumeration = request.getParameterNames();
String names = ",";
while (enumeration.hasMoreElements()) {
names += enumeration.nextElement().toString() + ",";
}
HashMap typemap = new HashMap();
ArrayList<String> collist = new ArrayList();
String sql = "update " + tablename + " set ";
Connection conn = this.getConn();
try {
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from " + tablename);
ResultSetMetaData rsmd = rs.getMetaData();
Enumeration enumeration = request.getParameterNames();
String names = ",";
while (enumeration.hasMoreElements()) {
names += enumeration.nextElement().toString() + ",";
}
HashMap typemap = new HashMap();
ArrayList<String> collist = new ArrayList();
String sql = "update " + tablename + " set ";
Connection conn = this.getConn();
try {
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from " + tablename);
ResultSetMetaData rsmd = rs.getMetaData();
int i = rsmd.getColumnCount();
System.out.println(i);
for (int j = 1; j <= i; j++) {
if (rsmd.getColumnName(j).equals("id")) continue;
if (rsmd.getColumnName(j).equals("ID")) continue;
if (rsmd.getColumnName(j).equals("Id")) continue;
if (rsmd.getColumnName(j).equals("iD")) continue;
typemap.put(rsmd.getColumnName(j) + "---", rsmd.getColumnTypeName(j));
collist.add(rsmd.getColumnName(j));
if (names.indexOf("," + rsmd.getColumnName(j) + ",") > -1) {
String[] values = request.getParameterValues(rsmd.getColumnName(j));
String value = "";
for (String vstr : values) {
if (vstr == null) vstr = "";
if (vstr.equals("null")) vstr = "";
if (vstr.trim().equals("")) continue;
if (request.getParameter(vstr) != null && !"".equals(request.getParameter(vstr)) && request.getParameter("dk-" + rsmd.getColumnName(j) + "-value") != null) {
String dkv = request.getParameter(vstr);
String dknamevalue = request.getParameter("dk-" + rsmd.getColumnName(j) + "-value");
vstr += " - " + dknamevalue + ":" + dkv;
System.out.println(vstr);
}
//if(vstr.length()<)
value += vstr + " ~ ";
}
if (value == null) value = "";
if (value.equals("null")) value = "";
if (value.length() > 0) value = value.substring(0, value.length() - 3);
if (rsmd.getColumnTypeName(j).equals("int")) {
sql += rsmd.getColumnName(j) + "=" + value + ",";
} else {
sql += rsmd.getColumnName(j) + "='" + value + "',";
}
*
*/
public static int dayToday(String DATE1, String DATE2) {
int i = 0;
if(DATE1.indexOf(" ")>-1)
DATE1 = DATE1.substring(0,DATE1.indexOf(" "));
if(DATE2.indexOf(" ")>-1)
DATE2 = DATE2.substring(0,DATE2.indexOf(" "));
String[] d1 = DATE1.split("-");
if(d1[1].length()==1)
{
DATE1 = d1[0]+"-0"+d1[1];
}else{
DATE1 = d1[0]+"-"+d1[1];
}
if(d1[2].length()==1)
{
DATE1 = DATE1+"-0"+d1[2];
}else{
DATE1 = DATE1+"-"+d1[2];
}
String[] d2 = DATE2.split("-");
if(d2[1].length()==1)
{
DATE2 = d2[0]+"-0"+d2[1];
}else{
DATE2 = d2[0]+"-"+d2[1];
}
if(d2[2].length()==1)
{
DATE2 = DATE2+"-0"+d2[2];
}else{
DATE2 = DATE2+"-"+d2[2];
}
for(int j=0;j<10000;j++)
{
i=j;
String gday = Info.getDay(DATE1, j);
if(gday.equals(DATE2))
{
break;
}
}
return i;
}
// 数据
protected Collection collection;
// 数据查询对象
protected CommDAO dao = new CommDAO();
// 表现层代码
protected String info;
// 请求路径
protected String path;
// 服务器请求对象
protected HttpServletRequest request;
/*
* 仅仅只是加到路径中去
*/
protected String parameter = "";
/**
*
* @param 下一页的分页链接
* @param 一页最大记录数
* @param 当前HttpServletRequest对象
* @param 数据库操作对象
*/
protected PageManager(String path, int pageSize, HttpServletRequest request) {
// 任意一个dao都行
this.currentPage = 1;
this.pageNumber = 1;
this.count = 0;
this.pageSize = pageSize <= 0 ? DEFAULTPAGESIZE : pageSize;
this.request = request;
this.path = path;
request.setAttribute("page", this);
try {
this.currentPage = Integer.parseInt(request
.getParameter("currentPage")) <= 0 ? 1 : Integer
.parseInt(request.getParameter("currentPage"));
}
response.setContentType("text/plain");
response.setHeader("Location",filename);
response.reset();
response.setHeader("Cache-Control", "max-age=0" );
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
try {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
// File f = new File(request.getRealPath("/upfile/")+"/"+filename);
//System.out.println(f);
bis = new BufferedInputStream((InputStream)new FileInputStream(request.getRealPath("/upfile/")+"/"+filename));
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos);
int bytesRead = 0;
byte[] buffer = new byte[5 * 1024];
while ((bytesRead = bis.read(buffer)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.close();
bis.close();
fos.close();
new Info().delPic(request.getRealPath("/upfile/")+"/", filename);
} catch (Exception e) {
}finally{
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
StringBuffer para = new StringBuffer("");
if (parameter != null && parameter.size() != 0) {
Iterator iterator = parameter.iterator();
while (iterator.hasNext()) {
para.append("&").append(iterator.next().toString());
}
}
this.parameter = para.toString();
}
/**
* 刷新分页路径
*
*/
protected void refreshUrl() {
StringBuffer buf = new StringBuffer();
buf.append("<font color='#1157B7'>共").append(count);
buf.append("条");
buf.append(" ");
buf.append("第").append(this.currentPage).append("/").append(
this.pageNumber).append("页");
buf.append(" ");
if (this.currentPage == 1)
buf.append("首页");
else
buf.append("<a href='").append(this.path).append("¤tPage=1")
.append(parameter)
.append("' class='ls'>").append("首页")
.append("</a>");
// #1157B7
buf.append(" ");
if (this.currentPage > 1) {
buf.append("<a href='").append(this.path).append("¤tPage=")
.append(currentPage - 1).append(parameter).append(
"' class='ls'>").append("上页")
.append("</a>");
} else {
buf.append("上页");
}
buf.append(" ");
int currentSegment = this.currentPage % segment == 0 ? this.currentPage
/ segment : this.currentPage / segment + 1;
/*for (int i = 1; i <= this.pageNumber; i++) {
if (this.currentPage == i)
buf.append("<font color='red'>").append(i).append("</font>");
else
buf.append("<a href='").append(this.path).append(
int i = rsmd.getColumnCount();
for (int j = 1; j <= i; j++) {
if (!rsmd.getColumnName(j).equals("ID")) {
String str = rs.getString(j) == null ? "" : rs.getString(j);
if (str.equals("null")) str = "";
map.put(rsmd.getColumnName(j), str);
} else
map.put("id", rs.getString(j));
}
list.add(map);
}
rs.close();
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list.get(0);
}
public HashMap getmaps(String nzd, String zdz, String table) {
List<HashMap> list = new ArrayList();
try {
Statement st = conn.createStatement();
//System.out.println("select * from "+table+" where "+nzd+"='"+zdz+"'");
ResultSet rs = st.executeQuery("select * from " + table + " where " + nzd + "='" + zdz + "'");
ResultSetMetaData rsmd = rs.getMetaData();
while (rs.next()) {
HashMap map = new HashMap();
int i = rsmd.getColumnCount();
for (int j = 1; j <= i; j++) {
if (!rsmd.getColumnName(j).equals("ID")) {
String str = rs.getString(j) == null ? "" : rs.getString(j);
if (str.equals("null")) str = "";
map.put(rsmd.getColumnName(j), str);
} else
map.put("id", rs.getString(j));
}
list.add(map);
}
rs.close();
st.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list.get(0);
}
public String insert(HttpServletRequest request, HttpServletResponse response, String tablename, HashMap extmap, boolean alert, boolean reflush, String tzurl) {
DATE2 = DATE2.substring(0,DATE2.indexOf(" "));
String[] d1 = DATE1.split("-");
if(d1[1].length()==1)
{
DATE1 = d1[0]+"-0"+d1[1];
}else{
DATE1 = d1[0]+"-"+d1[1];
}
if(d1[2].length()==1)
{
DATE1 = DATE1+"-0"+d1[2];
}else{
DATE1 = DATE1+"-"+d1[2];
}
String[] d2 = DATE2.split("-");
if(d2[1].length()==1)
{
DATE2 = d2[0]+"-0"+d2[1];
}else{
DATE2 = d2[0]+"-"+d2[1];
}
if(d2[2].length()==1)
{
DATE2 = DATE2+"-0"+d2[2];
}else{
DATE2 = DATE2+"-"+d2[2];
}
for(int j=0;j<10000;j++)
{
i=j;
String gday = Info.getDay(DATE1, j);
if(gday.equals(DATE2))
{
break;
if (rsmd.getColumnName(j).equals("Id")) continue;
typemap.put(rsmd.getColumnName(j) + "---", rsmd.getColumnTypeName(j));
collist.add(rsmd.getColumnName(j));
sql += rsmd.getColumnName(j) + ",";
}
sql = sql.substring(0, sql.length() - 1);
sql += ") values(";
rs.close();
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
Enumeration enumeration = request.getParameterNames();
String names = ",";
while (enumeration.hasMoreElements()) {
names += enumeration.nextElement().toString() + ",";
}
try {
Statement st = conn.createStatement();
for (String str : collist) {
if (names.indexOf("," + str + ",") > -1) {
String[] values = request.getParameterValues(str);
String value = "";
for (String vstr : values) {
if (vstr == null) vstr = "";
if (vstr.equals("null")) vstr = "";
if (vstr.trim().equals("")) continue;
if (request.getParameter(vstr) != null && !"".equals(request.getParameter(vstr)) && request.getParameter("dk-" + str + "-value") != null) {
String dkv = request.getParameter(vstr);
String dknamevalue = request.getParameter("dk-" + str + "-value");
vstr += " - " + dknamevalue + ":" + dkv;
}
value += vstr + " ~ ";
}
if (value == null) value = "";
if (value.equals("null")) value = "";
if (value.length() > 0) value = value.substring(0, value.length() - 3);
if (typemap.get(str + "---").equals("int")) {
sql += (value.equals("") ? -10 : value) + ",";
} else {
jscode+=" if(document.getElementsByName('"+strchname+"').length>0)\n";
jscode+=" {\n";
jscode+=" document.getElementsByName('"+strchname+"')[0].value='"+strch.substring(strch.lastIndexOf(":")+1)+"';\n";
jscode+=" }\n";
}
}
jscode+=" }\n";
jscode+=" }\n";
jscode+=" }\n";
jscode+=" if(radios.type=='select'){\n";
jscode+=" "+formname+"."+str1+".value=\""+str2+"\";\n";
jscode+=" }\n";
jscode+=" }else{\n";
jscode+=" if("+formname+"."+str1+")\n";
jscode+="{\n";
jscode+=""+formname+"."+str1+".value=\""+str2+"\";\n";
jscode+="}\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt\").src=\"upfile/"+map.get("filename")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt2\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt2\").src=\"upfile/"+map.get("filename2")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt3\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt3\").src=\"upfile/"+map.get("filename3")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt4\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt4\").src=\"upfile/"+map.get("filename4")+"\";\n";
jscode+="}\n";
jscode+="if(document.getElementById(\"txt5\"))\n";
jscode+="{\n";
jscode+="document.getElementById(\"txt5\").src=\"upfile/"+map.get("filename5")+"\";\n";
int i = rsmd.getColumnCount();
for (int j = 2; j <= i; j++) {
str += rsmd.getColumnName(j) + ",";
}
} catch (Exception e) {
e.printStackTrace();
}
str = str.substring(0, str.length() - 1);
return str;
}
public String update(HttpServletRequest request, HttpServletResponse response, String tablename, HashMap extmap, boolean alert, boolean reflush, String tzurl) {
if (request.getParameter("f") != null) {
Enumeration enumeration = request.getParameterNames();
String names = ",";
while (enumeration.hasMoreElements()) {
names += enumeration.nextElement().toString() + ",";
}
HashMap typemap = new HashMap();
ArrayList<String> collist = new ArrayList();
String sql = "update " + tablename + " set ";
Connection conn = this.getConn();
try {
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from " + tablename);
ResultSetMetaData rsmd = rs.getMetaData();
int i = rsmd.getColumnCount();
System.out.println(i);
for (int j = 1; j <= i; j++) {
if (rsmd.getColumnName(j).equals("id")) continue;
if (rsmd.getColumnName(j).equals("ID")) continue;
if (rsmd.getColumnName(j).equals("Id")) continue;
if (rsmd.getColumnName(j).equals("iD")) continue;
typemap.put(rsmd.getColumnName(j) + "---", rsmd.getColumnTypeName(j));
collist.add(rsmd.getColumnName(j));
if (names.indexOf("," + rsmd.getColumnName(j) + ",") > -1) {
String[] values = request.getParameterValues(rsmd.getColumnName(j));
String value = "";
for (String vstr : values) {
public class MainCtrl extends HttpServlet {
public MainCtrl() {
super();
}
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
dao.commOper(sql);
request.setAttribute("suc", "");
go("mod.jsp", request, response);
}
}
if(ac.equals("uploaddoc"))
{
try {
String filename="";
request.setCharacterEncoding("UTF-8");
RequestContext requestContext = new ServletRequestContext(request);
if(FileUpload.isMultipartContent(requestContext)){
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(request.getRealPath("/upfile/")+"/"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(100*1024*1024);
List items = new ArrayList();
items = upload.parseRequest(request);
FileItem fileItem = (FileItem) items.get(0);
if(fileItem.getName()!=null && fileItem.getSize()!=0)
{
if(fileItem.getName()!=null && fileItem.getSize()!=0){
File fullFile = new File(fileItem.getName());
filename = Info.generalFileName(fullFile.getName());
File newFile = new File(request.getRealPath("/upfile/")+"/" + filename);
try {
fileItem.write(newFile);
} catch (Exception e) {
e.printStackTrace();
}
}else{
}
}
}
go("/js/uploaddoc.jsp?docname="+filename, request, response);
} catch (Exception e1) {
e1.printStackTrace();
}
}
if(ac.equals("uploaddoc2"))
public class Info {
//public static String popheight = "alliframe.height=document.body.clientHeight+";
public static String popheight = "alliframe.style.height=document.body.scrollHeight+";
public static HashMap getUser(HttpServletRequest request)
{
HashMap map = (HashMap)(request.getSession().getAttribute("username")==null?request.getSession().getAttribute("user"):request.getSession().getAttribute("username"));
return map;
}
public static int getBetweenDayNumber(String dateA, String dateB) {
long dayNumber = 0;
//1小时=60分钟=3600秒=3600000
long mins = 60L * 1000L;
//long day= 24L * 60L * 60L * 1000L;计算天数之差
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
java.util.Date d1 = df.parse(dateA);
public class CommDAO {
public static String dbname = "";
public static String dbtype = "";
public static Connection conn = null;
public CommDAO() {
conn = this.getConn();
}
//给字段做加减法
public void jiajian(String tablename, String colname, String id, String num) {
HashMap map = this.getmap(id, tablename);
String value = map.get(colname).toString();
if (value.equals("")) value = "0";
int i = Integer.parseInt(value);
int j = Integer.parseInt(num);
commOper("update " + tablename + " set " + colname + " = " + (i + j) + " where id=" + id);
}
// 该方法返回一个table 用于流动图片
public String DynamicImage(String categoryid, int cut, int width, int height) {
StringBuffer imgStr = new StringBuffer();
StringBuffer thePics1 = new StringBuffer();
StringBuffer theLinks1 = new StringBuffer();
StringBuffer theTexts1 = new StringBuffer();
imgStr.append("<div id=picViwer1 style='background-color: #ffffff' align=center></div><SCRIPT src='js/dynamicImage.js' type=text/javascript></SCRIPT>\n<script language=JavaScript>\n");
thePics1.append("var thePics1=\n'");
theLinks1.append("var theLinks1='");
theTexts1.append("var theTexts1='");
List<HashMap> co = this.select("select * from xinwentongzhi where shouyetupian<>'' and shouyetupian<>'null' and shouyetupian like '%.jpg' order by id desc", 1, 6);
int i = co.size();
int j = 0;
for (HashMap b : co) {
j++;
int id = Integer.parseInt(b.get("id").toString());
String title = Info.subStr(b.get("biaoti").toString(), 21);
if (!(i < min || i > (max - 1))) {
mlist.add(list.get(i));
}
}
} catch (RuntimeException re) {
re.printStackTrace();
throw re;
}
return mlist;
}
public static void main(String[] args) {
}
}
package control;