编写一个留言簿程序,写入留言提交后显示留言内容
生活随笔
收集整理的這篇文章主要介紹了
编写一个留言簿程序,写入留言提交后显示留言内容
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
目錄
🍉題目
🥝實現(xiàn)過程
🍓代碼
🍑index.jsp
🍑show.jsp
🍑pane.jsp
🍉題目:
(1)編寫一個留言簿程序,寫入留言提交后顯示留言內容。
(2)寫入留言提交后顯示留言內容列表(提示:使用集合ArrayList、Vector存放留言列表)?
🥝實現(xiàn)過程:
在實現(xiàn)簡單留言板時,本人用三個JSP頁面來實現(xiàn),分別是:輸入頁面(index)、處理頁面(show)和顯示頁面(pane)。
輸入頁面有簡單三部分組成:姓名、標題和評論
🍓代碼:
🍑index.jsp
<%--Created by IntelliJ IDEA.User: 小賽毛Date: 2022/5/13Time: 11:10To change this template use File | Settings | File Templates. --%><%@page contentType="text/html;charset=gb2312" %> <html> <body> <form action="show.jsp" method="post" name="form">輸入名字:<input type="text" name="name" value=""><br>留言標題:<input type="text" name="title" value=""><br>留言:<br><textarea name="message" rows="10" cols="40" wrap="physical"></textarea><br><input type="submit" name="submit" value="提交"> </form> <a href="pane.jsp">查看留言板</a> </body> </html>🍑show.jsp
<%--Created by IntelliJ IDEA.User: 小賽毛Date: 2022/5/13Time: 11:19To change this template use File | Settings | File Templates. --%><%@page contentType="text/html;charset=gb2312" %> <%@page import="java.util.*"%> <html> <body> <%!Vector v=new Vector();//動態(tài)數(shù)組int i=0;ServletContext application;synchronized void leaveWord(String s){//方法聲明,用于在添加評論application=getServletContext();i++;v.add("No"+i+","+s);application.setAttribute("Mess",v);} %> <%request.setCharacterEncoding("gb2312");//亂碼處理String name=request.getParameter("name");//接收姓名String title=request.getParameter("title");//接收標題String message=request.getParameter("message");//接收評論if(name==null){name="guest"+(int)(Math.random()*10000);}if(title==null){title="無標題";}if(message==null){message="無信息";}String s=name+"#"+title+"#"+message;leaveWord(s);out.print("你的評論已提交!"); %> <a href="index.jsp">返回留言頁面</a> </body> </html>🍑pane.jsp
<%--Created by IntelliJ IDEA.User: 小賽毛Date: 2022/5/13Time: 11:18To change this template use File | Settings | File Templates. --%> <%@page contentType="text/html;charset=gb2312" %> <%@page import="java.util.*"%> <html> <body> <%request.setCharacterEncoding("gb2312");Vector v=(Vector)application.getAttribute("Mess");for(int i=0; i<v.size(); i++){String message=(String)v.elementAt(i);String []a=message.split("#");out.print("留言人:"+a[0]+",");out.print("標題:"+a[1]+"<br>");out.print("留言內容:"+a[2]+"<br>");} %> </body> </html>蟹蟹支持,繼續(xù)加油呀!!!?
總結
以上是生活随笔為你收集整理的编写一个留言簿程序,写入留言提交后显示留言内容的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux 环境变量配置全攻略,超详细~
- 下一篇: 二十三种设计模式彩图XXOO