idea编写留言板喊话功能和提示框

index.jsp

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/5/7 0007
  Time: 下午 4:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  <%
    if(session.getAttribute("message")!=null){
      out.println(session.getAttribute("message").toString());
    }
  %>
  <form action = "deal.jsp" method = "post" name = "form1" onsubmit="checkNull(form1)">
    <table>
      <tr>
        <td>留言人</td>
        <td><input type = "text" name = "author" id = "authId" title = "留言人"></td>
      </tr>
      <tr>
        <td>留言内容</td>
        <td> <textarea rows = "10" cols = "40" name = "content" id=“content"> </textarea></td>
      </tr>
      <tr>
        <td colspan = "2" align = "center">
        <input type = "submit" name = "submit1" value = "写留言">
        <input type = "reset" name = "submit2" value = "重置">
      </tr>
    </table>
  </form>
  <%@ include file ="bootom.jsp"%>
  <script type = "text/javascript">
    function checkNull(form) {
      for(i = 0;i<form.length;i++){

        if(form.elements[i].value==""){
          alert("抱歉"+form.elements[i].title+"不能为空");
          form.elements[i].focus();

          return false;
        }

      }

    }
  </script>

  <img src="bottom.jpg">
  </body>
</html>

deal.jsp


<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/5/8 0008
  Time: 上午 10:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    request.setCharacterEncoding("utf-8");
    response.setContentType("text/html;charset=utf-8");
    String author = request.getParameter("author");//获取留言人
    String content= request.getParameter("content");//获取留言内容
    String message = "["+author+"]说:"+content+"<br/>";//组合得到message
    if(session.getAttribute("massage")!=null){
        message+=session.getAttribute("message").toString();
    }
    session.setAttribute("message",message);//存入session
    response.sendRedirect("index.jsp");//重定向index.jsp页面
%>

</body>
</html>

在这里插入图片描述
在这里插入图片描述

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值