基于javaweb+JSP+Servlet简单留言板

基于javaweb+JSP+Servlet简单留言板

开发工具:eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>查看留言</title>
</head>
<body>
<table border="1" width="750px" align="center">
    <tr>
        <td colspan="2" align="center" bgcolor="yellow"><h2>留言板</h2></td>
<%--        <td>
            <form action="MessageServlet">
                <input type="hidden" name="type" value="query">
                <input type="submit" value="查看">
            </form>
        </td>--%>

                response.sendRedirect("lookreply.jsp");
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
package com.ser;

import com.bean.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

public class UserServlet extends HttpServlet {
    <tr>
        <td><%=message.getId()%></td>
        <td><%=message.getTitle()%></td>
        <td><%=message.getUsername()%></td>
        <td><%=message.getContent()%></td>
        <td><%=message.getTheme()%></td>
        <td><%=message.getTime()%></td>
    </tr>
    <tr>
        <td><a href="show.jsp" >点击返回</a></td>
    </tr>
</table>

<br><br>

</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" import="java.util.*,com.bean.Message"%>
<%@ page import="com.bean.User" %>
<%@ page import="com.bean.Reply" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

public class RegServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        User user=new User();
    <script type="text/javascript">

        // 检查注册时用户输入的注册信息是否正确
        function checkLogin() {
            var username = document.getElementById("text_username_login");
            if (username.value == "") {
                alert(new String("必须输入用户名!"));
                text_username_login.focus();
                return;
            }
            var password = document.getElementById("text_password_login");
            if (password.value == "") {
                alert("密码必须输入!");
                text_password_login.focus();
                return;
            }


            login_form.submit();
        }
    </script>
        <td align="center"><a href="MessageServlet?type=delete&id=<%=messages.get(i).getId() %>">删除</a></td>
        <% }%>
    </tr>
    <% }
    }
    %>

    <tr>
        <td colspan="3" align="center"><a href="message.jsp"><h3>添加新留言</h3></a></td>
    </tr>
</table>
<br><br>

</body>
        <td><%=message.getContent()%></td>
        <td><%=message.getTheme()%></td>
        <td><%=message.getTime()%></td>
    </tr>
    <tr>
        <td><a href="show.jsp" >点击返回</a></td>
    </tr>
</table>

<br><br>

</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
        return reContent;
    }
    public void setReContent(String reContent) {
        this.reContent = reContent;
    }
    //添加一条
    public void add(Reply reply) throws SQLException{
        //获取数据库连接
        Connection conn= Util.getConnection();
        PreparedStatement pre= conn.prepareStatement("INSERT INTO reply(mid,reusername,recontent) VALUES (?,?,?)");
        pre.setInt(1, reply.getMid());
        pre.setString(2,reply.getReUsername());
        pre.setString(3,reply.getReContent());
        pre.execute();
        System.out.println("插入一条记录");
        conn.close();
    }
    //查询所有
    public ArrayList<Reply> queryAll(int mid) throws SQLException {
        ArrayList<Reply> replies=new ArrayList<Reply>();
        ResultSet rs=null;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public String getTheme() {
        return theme;
    }

    public void setTheme(String theme) {
        this.theme = theme;
    }

    public String getTime() {
        return time;
    }
				
				messages=message.queryAll();
				
				request.getSession().setAttribute("messages", messages);
				
				response.sendRedirect("show.jsp");
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}else if(type.equals("delete")){
			User info = (User) request.getSession().getAttribute("info");
			if(info==null){
				request.getSession().setAttribute("info","删除留言请登录");
				response.sendRedirect("fail.jsp");
				return;
			}else{
				if(!info.getGrade().equals("admin")){
					request.getSession().setAttribute("info","非管理员不可删除");
					response.sendRedirect("fail.jsp");
					return;
				}
			}
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'userlogin.jsp' starting page</title>

运行环境

Java≥8、Tomcat≥8.0、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

技术框架

JSP Servlet MySQL JDBC Tomcat CSS JavaScript

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

发表留言,查看留言,回复留言,查看回复,删除留言(管理员)

20220314115024

20220314115038

20220314115049

20220314115126

20220314115147

20220314115228

20220314124832


  • 1
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
基于JavaWeb Servlet+JSP的量表系统可以通过以下步骤实现: 1.创建数据库表格,包括量表信息、题目信息、选项信息和用户答题记录信息等。 2.使用Servlet实现用户登录、注册、修改密码等功能。 3.使用JSP实现量表列表展示、量表详情展示、答题页面展示等功能。 4.使用ServletJSP实现用户答题记录的增加、查询、修改和删除等功能。 5.使用Bootstrap等前端框架美化页面,提高用户体验。 以下是一个简单的基于JavaWeb Servlet+JSP的量表系统的代码示例: 引用:基于JavaWeb Servlet+JSP+MYSQL+Bootstrap 文章管理系统 基于JavaWeb Servlet+JSP+MYSQL+Bootstrap 文章管理系统 基于JavaWeb Servlet+JSP+MYSQL+Bootstrap 文章管理系统 基于JavaWeb Servlet+JSP+MYSQL+Bootstrap ... 引用: ```java <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>量表详情</title> </head> <body> <h1>量表详情</h1> <table> <tr> <td>量表名称:</td> <td>${scale.name}</td> </tr> <tr> <td>量表描述:</td> <td>${scale.description}</td> </tr> <tr> <td>题目列表:</td> <td> <table> <c:forEach items="${scale.questions}" var="question"> <tr> <td>${question.content}</td> <td> <c:forEach items="${question.options}" var="option"> <input type="radio" name="${question.id}" value="${option.id}">${option.content} </c:forEach> </td> </tr> </c:forEach> </table> </td> </tr> </table> <form action="submit" method="post"> <input type="hidden" name="scaleId" value="${scale.id}"> <input type="submit" value="提交"> </form> </body> </html> ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值