JSP頁面構建簡單的下面是一個簡單的代碼來顯示wheather數據庫連接或
not.I我使用MySQL工作臺和netbeans.It是顯示未連接
和玻璃魚服務器顯示 代碼後顯示的一些警告。我的數據庫中,無法連接上的NetBeans
code
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Connection conn = null;
try{
Class.forName("com.mysql.jdbc.Driver");
conn =DriverManager.getConnection
("jdbc:mysql://localhost:3306/userpass?zeroDateTimeBehavior
=convertToNull","root", "root");
if(conn!=null)
{
out.print("connected to database successfully");
}
}catch(Exception e)
{
out.print("not connected to database");
}
%>
</body>
</html>
<warning and info*/
Info: Loading application __admingui done in 7,651 ms
Warning: Context path from ServletContext: differs from path from
bundle:/
Info: Redirecting to /index.jsf
Info: Admin Console: Initializing Session Attributes...
Warning: Could not open/create prefs root node Software\JavaSoft\Prefs at
root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Warning: Cannot create update center Image for C:\Program
Files\glassfish->4.1.1; Update Center functionality will not be available
in Admin Console
我只想說JSP中的Java腳本是錯誤的代碼。使用Servlet將結果傳遞給JSP並通過EL(表達式語言)進行打印。 對於你的問題,你應該添加玻璃魚的標籤。 – AxelH
@AxelH有一點要提,<% and %>之間的代碼不是Java腳本代碼,它是名爲scriplets的java代碼。是的,在我們有EL庫的日子裏編寫腳本是一種不好的做法。 JavaScript!= Java。 – drgPP
我沒有編寫javascript,而是使用java腳本,因爲當您將jsp寫入jsp標記之間的jsp時,這是調用scriptlet,我稱之爲Java腳本:PA位混淆,我承認,但是當我看到它時,我可以識別Java;) – AxelH