jsp聊天系統沒有使用數據庫的簡單介紹

本文目錄一覽:

代碼怎麼建立mysql數據庫,朋友給了我一個JSP系統,可是沒有數據庫。怎麼樣建立的數據庫才和系統吻合

這樣做比較費勁,首先你得看他的JSP系統是如何調用數據庫的,同時還得看JSP系統是直接讀取或寫入數據庫字段的還是通過存儲過程讀取或寫入數據庫的,如果是直接讀取的那根據JSP系統的字段名稱及類型建立數據庫中的表結構,如果是通過存儲過程操作數據庫的那就複雜了(如果是存儲過程調用的話,勸你還是放棄該系統,因為這樣你完全不知道數據庫的表結構)

jsp+servlet 用戶登錄 不用數據庫。新手java自學一個星期,求大神幫助。非常感謝!

你應該先判斷一下那個req.getParameter(“name”)和那個req.getParameter(“name”)是否為空.如果不判斷的話,它就會報那個語法錯誤的,因為這個頁面一打開的話,req.getParameter(“name”)和

req.getParameter(“name”)!=null並沒有被賦值,所以為空,肯定報錯的;

代碼應該這樣寫的:

if(req.getParameter(“name”)!=nullreq.getParameter(“name”)!=null){

String uname=req.getParameter(“name”);

String umm=req.getParameter(“mm”);

if(name.equals(uname)mm.equals(umm))

{

res.sendRedirect(“main.jsp”);

}

else

{

res.sendRedirect(“fail.jsp”);

}

}

用Jsp編寫無數據庫連接的簡單公共聊天室,用application和list相關知識編寫,請幫忙編寫一下。

JSP頁面:

%@ page language=”java” import=”java.util.*” pageEncoding=”gbk”%

%

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%”

titleMy JSP ‘index.jsp’ starting page/title

meta http-equiv=”pragma” content=”no-cache”

meta http-equiv=”cache-control” content=”no-cache”

meta http-equiv=”expires” content=”0″

meta http-equiv=”keywords” content=”keyword1,keyword2,keyword3″

meta http-equiv=”description” content=”This is my page”

!–

link rel=”stylesheet” type=”text/css” href=”styles.css”

/head

body

form action=”DoApplication” method=”post”

輸入聊天信息:

br /

textarea name=”talk” rows=”5″ cols=”40″/textarea

br /

input type=”submit” value=”確認”

input type=”reset” value=”清空”

/form

hr /

已有的聊天信息:

br /

%

List app = null;

app = (List) application.getAttribute(“app”);

if (app != null) {

%

textarea rows=”10″ cols=”40″ style=”text-align: left”

%

Iterator ite = app.iterator();

while (ite.hasNext()) {

String info = (String) ite.next();

%

%=info%

%

}

}

%

/textarea

/body

/html

————————————————

Severlet:

public class DoApplication extends HttpServlet {

/**

* Constructor of the object.

*/

public DoApplication() {

super();

}

/**

* Destruction of the servlet. br

*/

public void destroy() {

super.destroy(); // Just puts “destroy” string in log

// Put your code here

}

/**

* The doGet method of the servlet. br

*

* This method is called when a form has its tag value method equals to get.

*

* @param request the request send by the client to the server

* @param response the response send by the server to the client

* @throws ServletException if an error occurred

* @throws IOException if an error occurred

*/

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

String info=(String)request.getParameter(“talk”);

ServletContext application = this.getServletContext();

List appList=null;

appList=(List)application.getAttribute(“app”);

if(appList!=null){

appList.add(info);

}else{

appList=new ArrayList();

appList.add(info);

}

application.setAttribute(“app”, appList);

response.setCharacterEncoding(“gbk”);

request.getRequestDispatcher(“index.jsp”).forward(request, response);

}

/**

* The doPost method of the servlet. br

*

* This method is called when a form has its tag value method equals to post.

*

* @param request the request send by the client to the server

* @param response the response send by the server to the client

* @throws ServletException if an error occurred

* @throws IOException if an error occurred

*/

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

this.doGet(request, response);

}

/**

* Initialization of the servlet. br

*

* @throws ServletException if an error occurs

*/

public void init() throws ServletException {

// Put your code here

}

}

原創文章,作者:NDJV,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/145739.html

(0)
打賞 微信掃一掃 微信掃一掃 支付寶掃一掃 支付寶掃一掃
NDJV的頭像NDJV
上一篇 2024-10-27 23:52
下一篇 2024-10-27 23:52

相關推薦

  • Deepin系統分區設置教程

    本教程將會詳細介紹Deepin系統如何進行分區設置,分享多種方式讓您了解如何規劃您的硬盤。 一、分區的基本知識 在進行Deepin系統分區設置之前,我們需要了解一些基本分區概念。 …

    編程 2025-04-29
  • Python 常用數據庫有哪些?

    在Python編程中,數據庫是不可或缺的一部分。隨着互聯網應用的不斷擴大,處理海量數據已成為一種趨勢。Python有許多成熟的數據庫管理系統,接下來我們將從多個方面介紹Python…

    編程 2025-04-29
  • Python簡單數學計算

    本文將從多個方面介紹Python的簡單數學計算,包括基礎運算符、函數、庫以及實際應用場景。 一、基礎運算符 Python提供了基礎的算術運算符,包括加(+)、減(-)、乘(*)、除…

    編程 2025-04-29
  • openeuler安裝數據庫方案

    本文將介紹在openeuler操作系統中安裝數據庫的方案,並提供代碼示例。 一、安裝MariaDB 下面介紹如何在openeuler中安裝MariaDB。 1、更新軟件源 sudo…

    編程 2025-04-29
  • Python滿天星代碼:讓編程變得更加簡單

    本文將從多個方面詳細闡述Python滿天星代碼,為大家介紹它的優點以及如何在編程中使用。無論是剛剛接觸編程還是資深程序員,都能從中獲得一定的收穫。 一、簡介 Python滿天星代碼…

    編程 2025-04-29
  • 如何在樹莓派上安裝Windows 7系統?

    隨着樹莓派的普及,許多用戶想在樹莓派上安裝Windows 7操作系統。 一、準備工作 在開始之前,需要準備以下材料: 1.樹莓派4B一台; 2.一張8GB以上的SD卡; 3.下載並…

    編程 2025-04-29
  • Java任務下發回滾系統的設計與實現

    本文將介紹一個Java任務下發回滾系統的設計與實現。該系統可以用於執行複雜的任務,包括可回滾的任務,及時恢復任務失敗前的狀態。系統使用Java語言進行開發,可以支持多種類型的任務。…

    編程 2025-04-29
  • Python海龜代碼簡單畫圖

    本文將介紹如何使用Python的海龜庫進行簡單畫圖,並提供相關示例代碼。 一、基礎用法 使用Python的海龜庫,我們可以控制一個小海龜在窗口中移動,並利用它的“畫筆”在窗口中繪製…

    編程 2025-04-29
  • 數據庫第三範式會有刪除插入異常

    如果沒有正確設計數據庫,第三範式可能導致刪除和插入異常。以下是詳細解釋: 一、什麼是第三範式和範式理論? 範式理論是關係數據庫中的一個規範化過程。第三範式是範式理論中的一種常見形式…

    編程 2025-04-29
  • 分銷系統開發搭建

    本文主要介紹如何搭建一套完整的分銷系統,從需求分析、技術選型、開發、部署等方面進行說明。 一、需求分析 在進行分銷系統的開發之前,我們首先需要對系統進行需求分析。一般來說,分銷系統…

    編程 2025-04-29

發表回復

登錄後才能評論