(javaWeb-百斯特電子商城-在jsp頁面中側邊欄點擊,右邊進行變化(java實作)(持續完善)
- 1.問題描述:
- 2.開發環境:+解決思想+建議+注意
- 3.問題解決
- 3.1專案結構
- 3.2jsp
- index.jsp
- content.jsp
- footer.jsp
- header.jsp
- leftmenu.jsp
- topmenu.jsp
- 3.3 servlet
- 3.4 pojo
- 4.說明
- 5.效果展示
- 6.資源下載(不要錢,)
1.問題描述:
javaWeb作業做一個電子商城(功能持續完善中),現要求
1.用戶登陸后,還在本界面只顯示登陸成功與否(簡單不解釋)
2.點擊左側選單欄,右側進行變化還是當前界面,(詳細說明)
(因為前端沒有學習ajax所以對要求2用java實作,)
2.開發環境:+解決思想+建議+注意
開發環境:
1.eclipse ()
2.jdk8
解決思想
1.jsp界面是通過 <%@ include file="JSP/xxx.jsp" %>
拼接在一起的,
2.從 leftmenu.jsp我們可以看見:<li><a href="showProduct?category=101">手機數碼</a></li>
采用的是和doGet請求類似的方式 ,請求的url是 {showProduct} (相對),帶有一個引數category
可以用這個引數來進行分情況顯示,
3.寫一個ContentInfo的類(因為還沒有學pojo)來存放右側的資訊,右側資訊大體可以分為5部分,分別為 標題、圖片1、圖片2、正文1、正文2.
然后在寫一個showProductServlet來進行分類存放資訊,然后傳輸這個ContentInfo這個物體就行了,
建議:
1.分類存放建議放到servlet內,jsp界面只做顯示就行,
注意:
1.request.getParameter(""); 回傳的是String
2.request.getAttribute(""); 回傳的是Object
這里我們需要request.getAttribute("");然后強制型別轉換成(ContentInfo)
3.問題解決
3.1專案結構

3.2jsp
index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>百斯特電子商城</title>
<link href="css/style.css" rel="stylesheet" type ="text/css"/>
</head>
<body>
<div id= "container">
<div><br></div>
<div id="header"><%@ include file="JSP/header.jsp" %></div>
<div><br><br><br></div>
<div id="topmenu">
<%@ include file="JSP/topmenu.jsp" %>
</div>
<div><br><br></div>
<div id="mainContent" class= "clearfix">
<div id="leftmenu">
<%@ include file="JSP/leftmenu.jsp" %>
</div>
<div id="content">
<%@ include file="JSP/content.jsp" %>
</div>
</div>
<div id = "footer">
<%@ include file="JSP/footer.jsp" %>
</div>
</div>
</body>
</html>
content.jsp
<%@ page contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.wang.pojo.ContentInfo" %>
<%
ContentInfo contentInfo = new ContentInfo();
if((ContentInfo)request.getAttribute("contentInfo")==null){
contentInfo.setHeader("第一次沒有");
contentInfo.setImg1("./images/phone.jpg"/>
http://localhost:8080/chapter05/showProduct?category=101

http://localhost:8080/chapter05/showProduct?category=102

http://localhost:8080/chapter05/showProduct?category=103

http://localhost:8080/chapter05/showProduct?category=104

http://localhost:8080/chapter05/showProduct?category=105

6.資源下載(不要錢,)
https://download.csdn.net/download/qq_44218805/13089158
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/204431.html
標籤:其他
上一篇:學歷不是問題!笑談社招大專老哥阿里/騰訊/京東Java后端面試奇遇,輕松上岸入職京東!
下一篇:Java基礎面試寶典
