本文目錄一覽:
- 1、代碼怎麼建立mysql數據庫,朋友給了我一個JSP系統,可是沒有數據庫。怎麼樣建立的數據庫才和系統吻合
- 2、jsp+servlet 用戶登錄 不用數據庫。新手java自學一個星期,求大神幫助。非常感謝!
- 3、用Jsp編寫無數據庫連接的簡單公共聊天室,用application和list相關知識編寫,請幫忙編寫一下。
代碼怎麼建立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-hk/n/145739.html