本文目錄一覽:
- 1、jsp商城系統首頁主要代碼在哪個位置
- 2、jsp 中網站的首頁源代碼
- 3、需要一個可以運行的JSP簡單代碼?
- 4、JSP網上書店代碼 急啊!!!!簡單點就好,完後給100分
- 5、求大神寫一下jsp的簡單的註冊界面代碼。
jsp商城系統首頁主要代碼在哪個位置
任何位置。
javascript作為一種腳本語言可以放在html頁面中任何位置,但是瀏覽器解釋html時是按先後順序的,所以前面的script就先被執行。比如進行頁面顯示初始化的js必須放在head裡面,因為初始化都要求提前進行(如給頁面body設置css等)。而如果是通過事件調用執行的function那麼對位置沒什麼要求的。因而除了部分需要在網頁中輸出內容、調整顯示的JavaScript必須放在之間,一般的JavaScript放在和放在之間從執行結果來看是沒有區別的,但是有如下的經驗規則:
1.當JavaScript要在頁面載入過程中動態建立一些Web頁面的內容時,應將JavaScript放在body中。
2.定義為函數並用於頁面事件的JavaScript應當放在head標記中,因為它會在body之前載入。採用這種方法,頁面就不會被腳本搞得一團糟,易於閱讀,在每個頁面中,總可以在同一個位置找到腳本。
jsp 中網站的首頁源代碼
這是最簡單的一個例子,資料庫要你自己建,用的是ACCESS
%@ page contentType=”text/html; charset=gb2312″ language=”java” import=”java.sql.*” errorPage=”” %
html
head
meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″
titleJSP連接Access資料庫/title
style type=”text/css”
!–
.style1 {
font-size: 20px;
font-weight: bold;
}
—
/style
/headbody
div align=”center” class=”style1″JSP連接Access資料庫/div
br
hr
p%
Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver”); //載入驅動程序類別
Connection con = DriverManager.getConnection(“jdbc:odbc:jspdata”); //建立資料庫鏈接,jspdata為ODBC數據源名稱
//建立Statement對象
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = stmt.executeQuery(“select * from lyb”); //建立ResultSet(結果集)對象,並執行SQL語句
%
/p
p align=”center”NUMB1數據表中記錄如下/p
table width=”640″ border=”1″ align=”center” bordercolor=”#7188e0″
tr bgcolor=”d1d1ff”
th width=”49″編號/th
th width=”90″姓名/th
th width=”126″E-mail/th
th width=”221″網站/th
th width=”80″QQ/th
/tr
%
while(rs.next())
{
%
tr bgcolor=”#f8f8f8″
th%= rs.getString(1) %/th
th%= rs.getString(2) %/th
th%= rs.getString(3) %/th
th bgcolor=”#f6f6f8″%= rs.getString(4) %/th
th%= rs.getString(5) %/th
/tr
%
}
rs.close();
stmt.close();
con.close();
%
/table
p align=”center”br
如果您能看到表格中的數據,說明連接資料庫成功!/p
/body
/html
需要一個可以運行的JSP簡單代碼?
%@ page language=”java” import=”java.util.*” pageEncoding=”ISO-8859-1″%
%
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
This is my JSP page. br
/body
/html
JSP網上書店代碼 急啊!!!!簡單點就好,完後給100分
可以藉助Baiduhi告知我們你的題目
有空能處理你無法解決的題目
如果你有差不多的要求也能通知我們
ES:\\075FE838247AA6626CD75326A0C48EA9
交易提醒:預付定金有風險
交易提醒:百度名中包含聯繫方式勿輕信
求大神寫一下jsp的簡單的註冊界面代碼。
1.需要一個jsp頁面:
//login.jsp核心代碼:
form action=”${pageContext.request.contextPath}/servlet/UserServlet” method=”post”
input type=”text” name=”loginname” /input type=”password” name=”password”/
input type=”submit” value=”登錄”/
/form
2.需要一個servlet來驗證登錄信息
//UserServlet 核心代碼
class UserServlet extends HttpServlet{
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
private void process(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
request.setCharacterEncoding(“UTF-8”);
response.setContentType(“text/html”);
String loginname = request.getParameter(“loginname”);
String password = request.getParameter(“password”);
//創建一個service來處理業務邏輯(包括查詢資料庫操作)
UserService service = new UserService();
boolean bool = service.validateUser(loginname,password);
if(!bool){
pw.println(“用戶名或密碼錯誤”);
}else{
pw.println(“登錄成功”);
}
}
3.需要一個service處理業務邏輯(包括查詢資料庫操作)
//UserService 核心代碼
public class UserService{
/**
*查詢資料庫驗證用戶是否存在,返回boolean
*/
public boolean validateUser(String loginname,String password){
boolean bool = false;
Connection conn = null;
PreparedStatement ps = null;
//這裡以mysql為例
try {
Class.forName(“com.mysql.jdbc.Driver”).newInstance();
conn = DriverManager.getConnection(“jdbc:mysql://localhost:3306/test”, “root”, “”);
String sql = “select login_name,pass_word from t_user where login_name=? and pass_word=?”;
ps = conn.prepareStatement(sql);
ps.setString(0, loginname);
ps.setString(1, password);
ResultSet rs = ps.executeQuery();
if(rs.next()){
bool = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(conn != null){
conn.close();
conn = null;
}
if(ps != null){
ps.close();
ps = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return bool;
}
}
原創文章,作者:簡單一點,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/128920.html