sendMess.java
上传用户:manager48
上传日期:2022-07-31
资源大小:997k
文件大小:2k
- /*****************************************************************
- * Date:2007-05-10 *
- * File:sendMess.java *
- * Author:jezz *
- *****************************************************************/
- package wm.servlet;
- import java.util.*;
- import java.sql.*;
- import java.io.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import wm.bean.messFun;
- public class sendMess extends HttpServlet{
-
-
- public void init()throws ServletException
- {
- }
-
- public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
- {
- messFun MF=new messFun();//创建功能对象
- String username="";
- String email="";
- String content="";
- String restore="";
- String msg="";//自定义错误信息
- username=request.getParameter("yhm");
- email=request.getParameter("email");
- content=request.getParameter("content");
- String ip=request.getRemoteHost();
- String sj=MF.gettime();
- if(username=="")
- msg+="<li>用户名不能为空</li>";
- else if(!(MF.validLength(username,3,12)))//验证内容的合法性
- msg+="<li>用户名应在3到12位之间</li>";
- if(email=="")
- msg+="<li>邮箱不能为空</li>";
- else if(email.equals("")||(email.indexOf('@')==-1)||(email.indexOf('.')==-1))
- msg+="<li>邮箱格式不正确</li>";
- if(content=="")
- msg+="<li>内容不能为空</li>";
- else if(!(MF.validLength(content,10,512)))
- msg+="<li>内容应该在10和100字符之间</li>";
- response.setContentType("text/html;charset=GBK");
- if(msg.equals(""))//如果没有错误
- {
- boolean result=MF.addMess(ip,email,sj,content,restore,username);
- if(result==true)
- msg+="留言成功";
- else
- msg+="留言失败";
- request.setAttribute("msg",msg);
- RequestDispatcher wm=request.getRequestDispatcher("common.jsp");
- wm.forward(request,response);
- }
- else
- {
- request.setAttribute("msg",msg);
- RequestDispatcher wm=request.getRequestDispatcher("common.jsp");
- wm.forward(request,response);
- }
- }
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException
- {
- doGet(request, response);
- }
- //Clean up resources
- public void destroy()
- {
- }
- }