码迷,mamicode.com
首页 > 其他好文 > 详细

一个简陋的留言板

时间:2020-01-07 20:08:17      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:input   tchar   nbsp   enc   etc   method   submit   留言板   ram   

【效果图】
技术图片
技术图片
技术图片

就两个jsp文件搞定
example2_1.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>留言板</title>
        <style>
            .userinput{
                width:100px;
            }
        </style>
    </head>
    <body>
        <form action="sub.jsp" method="post">
            Name: &nbsp; <input class="userinput" type="text" name="user" /><br>
            Content:<br/>
            <textarea value="" name="newwords" cols="20" rows="3">
            </textarea>
            <br>
            <input type="submit" value="submit"/>
        </form>
        <br>
        <a href="sub.jsp">view comments</a>
    </body>
</html>

sub.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>example3_1</title>
    </head>
    <body>
        <%
            request.setCharacterEncoding("utf-8");
            if (application.getAttribute("mainboard")==null){
                application.setAttribute("mainboard", "");
            }
            String cur = (String)application.getAttribute("mainboard");
            if (!(request.getParameter("user")==null) &&
                    !(request.getParameter("newwords")==null)){
                String user = request.getParameter("user");
                String words = request.getParameter("newwords");

                if (cur.length()!=0){
                    cur = cur + "<br>";
                }
                cur = cur + user+":";
                cur = cur + words;
                application.setAttribute("mainboard", cur);
            }
            out.print(cur);
        %> 
        <br><br>
        <a href="example2_1.jsp">返回</a>
    </body>
</html>

一个简陋的留言板

标签:input   tchar   nbsp   enc   etc   method   submit   留言板   ram   

原文地址:https://www.cnblogs.com/AWCXV/p/12163341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!