JSP开发自定义公告栏

1.描述:JSP开发自定义公告栏,可以自己输入公告内容然后进行公告显示

2.前期:需要Tomcat服务器、JDK

3.原理:使用request对象获取提交到本页面的表单信息,然后通过表达式语言在marquee标签中进行输出

4.代码:

<%@ page language="java" contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>JSP</title>
</head>
<body>
    <%
        request.setCharacterEncoding("UTF-8");          // 设置编码防止中文出现乱码
        String info = request.getParameter("content");  // 获取表单内容

        // 表单提交到本身页面必须进行null判断
        info = (info == null)? "" : info;               // 判断内容是否为空
    %>

    <%-- 使用marquee标签, 在其中使用表达式进行输出 --%>
    <marquee behavior="scroll" direction="right">
        <%=info%>
    </marquee>

    <%-- 表单提交到本身页面 --%>
    <form action="myjsp.jsp" method="POST">
        <label for="conteny">请输入公告信息:</label>
        <input type="text" id="conteny" name="content" />
        <input type="submit" value="发布" />
        <input type="reset" value="重置" />
    </form>
</body>
</html>
5.运行结果

6.提示:如果看到这篇文章,相信朋友的JavaWeb开发环境已经搭建好

猜你喜欢

转载自blog.csdn.net/sinat_34104446/article/details/79812563