最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Java web:JSP,登錄,創(chuàng)建商品類,行為標簽指令在頁面上顯示賦值的內(nèi)容【詩書畫唱】

2020-09-04 08:18 作者:詩書畫唱  | 我要投稿

1、創(chuàng)建一個商品類,包含編號,名稱和價格,通過jsp的行為標簽(就是用創(chuàng)建一個商品類,并給他的所有屬性賦值。最后在頁面上顯示賦值的內(nèi)容。

package com.SSHC;


public class ShangPin {

private String? bianHao;


private String? name;

private Double? price;

public String getBianHao() {

return bianHao;

}

public void setBianHao(String bianHao) {

this.bianHao = bianHao;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Double getPrice() {

return price;

}

public void setPrice(Double price) {

this.price = price;

}

}



<%@ page language="java" contentType="text/html; charset=UTF-8"

?pageEncoding="UTF-8"%>

<%

? ? 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>

? ?

? ? ? ??

? ? ? ? <title>詩書畫唱提醒你!跟我學JSP行為!</title>

? ? ? ??

? ? ? ? <!-- 下面的meta在這里刪掉都沒太多影響 -->

? ? ? ? <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">

? ? </head>

? ? <body>


? ? ??

? ? ? <!-- 下面的是給ShangPin取別名為s。

? ? ? Bean是描述Java的軟件組件模型? -->

<jsp:useBean id="s" class="com.SSHC.ShangPin"></jsp:useBean>

? ? ? <!-- property="屬性名" name="類的別名" value="自己設(shè)置

? ? ? 和賦值的屬性值。自己的翻譯:setProperty為設(shè)置配置"。

? ? ? property:特性;性質(zhì);性能;-->

<jsp:setProperty property="bianHao" name="s" value="666"/>

? ? <jsp:setProperty property="name" name="s" value="詩書畫唱CD"/>

? ? <jsp:setProperty property="price" name="s" value="6666.66"/>??

? ? ? ? <jsp:getProperty property="bianHao" name="s"/>

? ? ? ? ?<jsp:getProperty property="name" name="s"/>

? ? ? ? ? <jsp:getProperty property="price" name="s"/>

? ? ? ?

? ? </body>

</html>





2、創(chuàng)建一個注冊頁面reg.jsp,包含賬號,密碼,性別(單選框),愛好(多選框)和學歷(下拉框),生日(日期框),通過表單提交方式提交到doReg.jsp,獲取表單中的所有數(shù)據(jù)并打印出來,注意中文亂碼處理。


<%@ page language="java" contentType="text/html;?

charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? 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>

? ? ?

? ? ? ? <title></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">

? ? ? ? <style type="text/css">

? ? ? ? ? ? *{

? ? ? ? ? ? ? ? font-size:23px;

? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ??

? ? ? ? ? ? }

? ? ? ? ? ??

? ? ? ? </style>

? ? </head>

? ? <body>

? ? ? ? <h1>注冊頁面</h1>

? ? ? ? <form action="doReg.jsp" method="post">

? ? ? ? ? ? <table border="1" >

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>賬號:</td>

? ? ? ? ? ? ? ? ? ? <td><input type="text" name="zhangHao" /></td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>密碼:</td>

? ? ? ? ? ? ? ? ? ? <td><input type="password" name="pwd" /></td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>確認密碼:</td>

? ? ? ? ? ? ? ? ? ? <td><input type="password" name="pwdSure" /></td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? ?<tr>

? ? ? ? ? ? ? ? ? ? <td>生日</td>

? ? ? ? ? ? ? ? ? ? <td>

? ? ? ? ? ? ? ? ? ? <!-- type="date" 是HTML5中才有很好效果的

? ? ? ? ? ? ? ? ? ? 代碼,在這里和 type="text"沒有太多的區(qū)別-->

? ? ? ? ? ? ? ? ? ? ? ?<input type="date" name="brithday" />

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>學歷</td>

? ? ? ? ? ? ? ? ? ? <td>

? ? ? ? ? ? ? ? ? ? ? ? <select name="xueLi">

? ? ? ? ? ? ? ? ? ? ? ? ? ? <option value="">請選擇學歷</option>

? ? ? ? ? ? ? ? ? ? ? ? ? ? <option value="1">本科</option>

? ? ? ? ? ? ? ? ? ? ? ? ? ? <option value="2">大專</option>

? ? ? ? ? ? ? ? ? ? ? ? ? ? <option value="3">高中</option>

? ? ? ? ? ? ? ? ? ? ? ? ? ? <option value="4">初中</option>

? ? ? ? ? ? ? ? ? ? ? ? </select>

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>性別:</td>

? ? ? ? ? ? ? ? ? ? <td>

? ? ? ? ? ? ? ? ? ? ? ? <input type="radio" name="sex"?

? ? ? ? ? ? ? ? ? ? ? ? value="男" checked />男

? ? ? ? ? ? ? ? ? ? ? ? <input type="radio" name="sex"

? ? ? ? ? ? ? ? ? ? ? ? ?value="女" />女

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>愛好:</td>

? ? ? ? ? ? ? ? ? ? <td>

?<input type="checkbox" name="aiHao" value="唱歌和給詩書畫唱三連"?

? checked/>唱歌和給詩書畫唱三連

? <input type="checkbox" name="aiHao"?

? value="跳舞和給詩書畫唱關(guān)注" />跳舞和給詩書畫唱關(guān)注

<input type="checkbox" name="aiHao" value="看書和詩書畫唱的視頻" />

看書和詩書畫唱的視頻

?<input type="checkbox" name="aiHao" value="rap" />rap

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td colspan="2" align="center">

? ? ? ? ? ? ? ? ? ? ? ? <input type="reset" value="重置" />

? ? ? ? ? ? ? ? ? ? ? ? <input type="submit" value="提交" />

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? </table>

? ? ? ? </form>

? ? </body>

</html>



這里的學歷打印的是value中的值,把其中的1改成“本科”等就可以了



3、創(chuàng)建一個商品新增頁面add.jsp,要求輸入名稱和價格,通過表單提交到doAdd.jsp頁面,將獲取到的商品名稱和價格封裝到商品對象中(可以復(fù)用第1題中的商品類)

package com.SSHC;


public class ShangPin {

private String? bianHao;


private String? name;

private Double? price;

public String getBianHao() {

return bianHao;

}

public void setBianHao(String bianHao) {

this.bianHao = bianHao;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Double getPrice() {

return price;

}

public void setPrice(Double price) {

this.price = price;

}

}



<%@ page language="java" contentType="text/html;?

charset=UTF-8" pageEncoding="UTF-8"%>

<%

? ? 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>

?

? ? ? ? <title></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">

? ? ? ? <style type="text/css">

? ? ? ? ? ? *{

? ? ? ? ? ? ? ? font-size:23px;

? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ??

? ? ? ? ? ? }

? ? ? ? ? ??

? ? ? ? </style>

? ? </head>

? ? <body>

? ? ? ? <h1>商品界面</h1>

? ? ? ? <form action="doAdd.jsp" method="post">

? ? ? ? ? ? <table border="1" >

? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>商品名稱:</td>

? ? ? ? ? ? ? ? ? ? <td><input type="text" name="spName" /></td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td>商品價格:</td>

? ? ? ? ? ? ? ? ? ? <td><input type="text" name="spPrice" /></td>

? ? ? ? ? ? ? ? </tr>? ?

? ? ? ? ? ? ? ? ? ? <tr>

? ? ? ? ? ? ? ? ? ? <td colspan="2" align="center">

? ? ? ? ? ? ? ? ? ? ? ? <input type="reset" value="重置" />

? ? ? ? ? ? ? ? ? ? ? ? <input type="submit" value="提交" />

? ? ? ? ? ? ? ? ? ? </td>

? ? ? ? ? ? ? ? </tr>

? ? ? ? ? ? </table>

? ? ? ? </form>

? ? </body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

?pageEncoding="UTF-8"%>

<%

? ? 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>

? ?

? ?

? ? ? ??

? ? ? ? <title>詩書畫唱提醒你!跟我學JSP行為!</title>

? ? ? ??

? ? ? ? <!-- 下面的meta在這里刪掉都沒太多影響 -->

? ? ? ? <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">

? ? </head>

? ? <body>


<%

? ? //下面是用request處理中文亂碼:

? ? request.setCharacterEncoding("utf-8");


String spName= request.getParameter("spName");

System.out.println("商品名稱:"+spName);

String spPrice= request.getParameter("spPrice");

System.out.println("商品價格:"+spPrice);

/**值得注意的是這里要把String類型轉(zhuǎn)換成Double類型等,因為在自己寫的

shangPin類中,Price為Double類型,在用下面的

JSP動作指令插入Double類型內(nèi)容中時,不這樣的話,就會報錯等*/

Double spPriceDouble=Double.valueOf(spPrice);

%>

? ? ??

? ? ? <!-- 下面的是給ShangPin取別名為s。

? ? ? Bean是描述Java的軟件組件模型? -->

<jsp:useBean id="s" class="com.SSHC.ShangPin"></jsp:useBean>

? ? ? <!-- property="屬性名" name="類的別名" value="自己設(shè)置

? ? ? 和賦值的屬性值。自己的翻譯:setProperty為設(shè)置配置"。

? ? ? property:特性;性質(zhì);性能;-->

<jsp:setProperty property="name" name="s" value="<%=spName%>"/>

? ? <jsp:setProperty property="price" name="s"?

? ? value="<%=spPriceDouble%>"/>

<!-- 下面是得到內(nèi)容,之后可以打印,顯示到網(wǎng)頁上 -->

? ? ? ? ?<jsp:getProperty property="name" name="s"/>

? ? ? ? ? <jsp:getProperty property="price" name="s"/>

? ? ? ?

? ? </body>

</html>




推薦文章:


Bean是描述Java的軟件組件模型?

http-equiv顧名思義,相當于http的文件頭作用,

它可以向瀏覽器傳回一些有用的信息,以幫助正確和精確地顯示網(wǎng)頁內(nèi)容,

與之對應(yīng)的屬性值為content,

?content中的內(nèi)容其實就是各個參數(shù)的變量值。???

https://www.cnblogs.com/dreamaker/p/10576750.html


推薦網(wǎng)站:

https://developer.aliyun.com/?spm=a2c6h.12873639.fszjobuve.3.4eb74ea4irbQAb



Java web:JSP,登錄,創(chuàng)建商品類,行為標簽指令在頁面上顯示賦值的內(nèi)容【詩書畫唱】的評論 (共 條)

分享到微博請遵守國家法律
衡山县| 绥棱县| 游戏| 澄城县| 岫岩| 边坝县| 革吉县| 金昌市| 阳原县| 中超| 昔阳县| 凤台县| 宣汉县| 和顺县| 绥宁县| 阳信县| 永昌县| 宁安市| 汶上县| 本溪| 青浦区| 靖江市| 莫力| 芜湖县| 固阳县| 拉孜县| 宁武县| 厦门市| 手机| 登封市| 蕉岭县| 安泽县| 烟台市| 太谷县| 皮山县| 浙江省| 裕民县| 伊川县| 邻水| 大新县| 桃源县|