modquestion.jsp
上传用户:apbaoyuan
上传日期:2021-02-12
资源大小:1015k
文件大小:2k
源码类别:

Jsp/Servlet

开发平台:

HTML/CSS

  1. <%@page import="java.sql.*"%>
  2. <%@page import="java.util.*"%>
  3. <%@page contentType="text/html;charset=GB2312"%>
  4. <%@include file="opendata.jsp"%>
  5. <%@include file="check.jsp"%>
  6. <%!
  7.  int isempty(String str)  //判断递交的字符串是否为空
  8.  {
  9.   if(str.length() ==0)
  10.     return (0);
  11.   else return (1);
  12.  }
  13. %>
  14. <%!
  15.  String transfer(int i)   //将时间数值转换为标准格式
  16.  {
  17.   if(i>=10)
  18.     return (String.valueOf(i));
  19.   else return ("0"+String.valueOf(i));
  20.  }
  21. %>
  22. <%
  23. try{
  24.  request.setCharacterEncoding("GB2312");
  25.  String question = request.getParameter("question");
  26.  int questionid = Integer.parseInt(request.getParameter("questionid"));
  27.  int year,month,day,hour,minute,second;
  28.  String time;
  29.  GregorianCalendar calendar;
  30.  calendar = new GregorianCalendar();
  31.  year = calendar.get(Calendar.YEAR);
  32.  month = calendar.get(Calendar.MONTH)+1;
  33.  day = calendar.get(Calendar.DAY_OF_MONTH);
  34.  hour = calendar.get(Calendar.HOUR_OF_DAY);
  35.  minute = calendar.get(Calendar.MINUTE);
  36.  second = calendar.get(Calendar.SECOND);
  37.  time = year +"-"+transfer(month)+"-" + transfer(day) +" "+transfer(hour)+":"+transfer(minute)+":"+transfer(second);
  38. if(question.length()==0)
  39.  {
  40.   String errmsg = "问题不可为空!!!";
  41.   out.print("<center><font color=green size=5>错误信息<hr></font><font color=red>"+errmsg+"</font><hr>");
  42.   out.print("<input type=button value=回上一页 onclick=history.back()>");
  43.  }
  44.  else
  45.  {
  46.  //更新主题
  47.  sql = "update Questions set Question = '"+question+"',Date = '"+time+"',IsVisable = 0 where QuestionID = "+questionid;
  48.  smt.executeUpdate(sql);
  49.  response.sendRedirect("edit.jsp?questionid="+questionid);
  50.  }}
  51.   catch (Exception e) {
  52. e.getStackTrace();
  53. }
  54. %>
  55. <html>
  56. <title>错误信息</title>
  57. </html>