首页 > 编程知识 正文

jsp聊天系统没有使用数据库的简单介绍

时间:2023-12-24 12:05:33 阅读:320520 作者:JBYK

本文目录一览:

代码怎么建立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

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。