相关文章
更多最近更新
更多一段很简单代码的疑问
2019-03-25 13:40|来源: 网路
这是截取一本书里的一个demo项目的action代码:
//封装货物基本信息
public Goods getGoodsBean(HttpServletRequest req, HttpServletResponse res) {
Goods goods = new Goods();
try {
//判断是否是新增或者修改还是删除,如果是新增则不需要id
String hh = req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
if (!"".equals(hh) && hh != null) {
goods.setId(Integer.valueOf(req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "")));
}
//设定货物名
goods.setName(((String)req.getParameter("name" + (String)req.getParameter("checkbox") + "")));
//设定货物价格
goods.setPrice(Double.parseDouble(((String)req.getParameter("price" + (String)req.getParameter("checkbox") + ""))));
//设定货物数量
goods.setCount(Integer.parseInt(((String)req.getParameter("count" + (String)req.getParameter("checkbox") + ""))));
//设定货物发布日期
goods.setReleaseDate(getCurrentDate());
} catch (Exception ex) {
ex.printStackTrace();
}
return goods;
}
请问:
String hh = req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
"goodsId"是字段吗? String)req.getParameter("checkbox") 这是提取("checkbox")里的值吗?
这句怎么理解呢?
问题补充:
您好您的意思是这样的吗:
hh=req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "")
提取的jsp中 goodsIdxxx+空格 元素的值吗(假如(String)req.getParameter("checkbox") 返回的是xxx)。
现在就有另外一个问题了 jsp中的checkbox元素类型是checkbox,那返回的是什么啊。
还有jsp页面中没有 goodsIdxxx+空格 这个元素 :
注:我看的书《我的J2EE成功之路》 郭峰 著作 电子工业出版社
第18章的demo
问题补充:
这本书我没看过,但是
(String)req.getParameter("checkbox") 返回的是xxx 这句取得是一个name属性为checkbox的元素,而不是checkbox复选款的值,因为checkbox是复选款,所有可能会有几个这样的东西<input type="checkbox" name="a">,要取checkbox复选框的值,那么后台应该这样写:req.getParameters("a");返回的是一个数组,数组就是复选框各个选项的值;
"goodsId" + (String)req.getParameter("checkbox") + "",是字符串相加,""是空字符,而不是空格,提取的jsp中 goodsIdxxx的值
不好意思再麻烦您一下:
jsp代码是这样的。
那goodsIdxxx到底是那个啊?
问题补充:
这本书我没看过,但是
(String)req.getParameter("checkbox") 返回的是xxx 这句取得是一个name属性为checkbox的元素,而不是checkbox复选款的值,因为checkbox是复选款,所有可能会有几个这样的东西<input type="checkbox" name="a">,要取checkbox复选框的值,那么后台应该这样写:req.getParameters("a");返回的是一个数组,数组就是复选框各个选项的值;
"goodsId" + (String)req.getParameter("checkbox") + "",是字符串相加,""是空字符,而不是空格,提取的jsp中 goodsIdxxx的值
谢谢了 看了好久终于明白了
<
中的 "count<%=m%>" 是个字符串 <%=m%> 是个函数返回的也是字符串
再请问下 您觉得我要在学习 javaweb 的话 现在最需要把那学地方搞懂
(您对我的评价就参照我我所提的问题就可以了) 我是自学的 所以还想请您推荐一下一些好书、
//封装货物基本信息
public Goods getGoodsBean(HttpServletRequest req, HttpServletResponse res) {
Goods goods = new Goods();
try {
//判断是否是新增或者修改还是删除,如果是新增则不需要id
String hh = req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
if (!"".equals(hh) && hh != null) {
goods.setId(Integer.valueOf(req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "")));
}
//设定货物名
goods.setName(((String)req.getParameter("name" + (String)req.getParameter("checkbox") + "")));
//设定货物价格
goods.setPrice(Double.parseDouble(((String)req.getParameter("price" + (String)req.getParameter("checkbox") + ""))));
//设定货物数量
goods.setCount(Integer.parseInt(((String)req.getParameter("count" + (String)req.getParameter("checkbox") + ""))));
//设定货物发布日期
goods.setReleaseDate(getCurrentDate());
} catch (Exception ex) {
ex.printStackTrace();
}
return goods;
}
请问:
String hh = req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
"goodsId"是字段吗? String)req.getParameter("checkbox") 这是提取("checkbox")里的值吗?
这句怎么理解呢?
问题补充:
missoasis 写道
req.getParameter("checkbox") 中checkbox是一个参数,是jsp页面中一个name名为checkbox的元素,req.getParameter("checkbox")是取得name为checkbox的元素的值
req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
中goodsId是一个字符串而已,这个字符串+req.getParameter("checkbox")返回的值组成一个新的字符串,这个新的字符串跟checkbox一样,也是jsp页面中一个name为这个新字符串的元素,hh就是这个元素的值
req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
中goodsId是一个字符串而已,这个字符串+req.getParameter("checkbox")返回的值组成一个新的字符串,这个新的字符串跟checkbox一样,也是jsp页面中一个name为这个新字符串的元素,hh就是这个元素的值
missoasis 写道
req.getParameter("checkbox") 中checkbox是一个参数,是jsp页面中一个name名为checkbox的元素,req.getParameter("checkbox")是取得name为checkbox的元素的值
req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
中goodsId是一个字符串而已,这个字符串+req.getParameter("checkbox")返回的值组成一个新的字符串,这个新的字符串跟checkbox一样,也是jsp页面中一个name为这个新字符串的元素,hh就是这个元素的值
req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "");
中goodsId是一个字符串而已,这个字符串+req.getParameter("checkbox")返回的值组成一个新的字符串,这个新的字符串跟checkbox一样,也是jsp页面中一个name为这个新字符串的元素,hh就是这个元素的值
您好您的意思是这样的吗:
hh=req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "")
提取的jsp中 goodsIdxxx+空格 元素的值吗(假如(String)req.getParameter("checkbox") 返回的是xxx)。
现在就有另外一个问题了 jsp中的checkbox元素类型是checkbox,那返回的是什么啊。
还有jsp页面中没有 goodsIdxxx+空格 这个元素 :
注:我看的书《我的J2EE成功之路》 郭峰 著作 电子工业出版社
第18章的demo
问题补充:
missoasis 写道
引用
hh=req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "")
提取的jsp中 goodsIdxxx+空格 元素的值吗(假如(String)req.getParameter("checkbox") 返回的是xxx)。
现在就有另外一个问题了 jsp中的checkbox元素类型是checkbox,那返回的是什么啊。
还有jsp页面中没有 goodsIdxxx+空格 这个元素 :
注:我看的书《我的J2EE成功之路》 郭峰 著作 电子工业出版社
提取的jsp中 goodsIdxxx+空格 元素的值吗(假如(String)req.getParameter("checkbox") 返回的是xxx)。
现在就有另外一个问题了 jsp中的checkbox元素类型是checkbox,那返回的是什么啊。
还有jsp页面中没有 goodsIdxxx+空格 这个元素 :
注:我看的书《我的J2EE成功之路》 郭峰 著作 电子工业出版社
这本书我没看过,但是
(String)req.getParameter("checkbox") 返回的是xxx 这句取得是一个name属性为checkbox的元素,而不是checkbox复选款的值,因为checkbox是复选款,所有可能会有几个这样的东西<input type="checkbox" name="a">,要取checkbox复选框的值,那么后台应该这样写:req.getParameters("a");返回的是一个数组,数组就是复选框各个选项的值;
"goodsId" + (String)req.getParameter("checkbox") + "",是字符串相加,""是空字符,而不是空格,提取的jsp中 goodsIdxxx的值
不好意思再麻烦您一下:
jsp代码是这样的。
<%@page contentType="text/html;charset=GBK"%> <%@page import="java.util.*,com.webShopping.domain.*"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=GBK"> <title>货物管理画面</title> </head> <!--获取已有的货物--> <% List listGoodss = (List)request.getAttribute("listGoodss"); //获取已有的货物类别 List listGoodsTypes = (List)request.getAttribute("listGoodsTypes"); //设定系统中共有多少个货物已注册 int m = 0; %> <body> <form name="form1" action=" method="post"> <table width="776" border="1"> <tr> <td height="38" colspan="6"><div align="center">消息提示:${msg}</div></td> </tr> <tr> <td height="27">选择</td> <td>货物名称</td> <td>货物价格</td> <td>货物件数</td> <td>货物类别</td> <td>货物发布日期</td> </tr> <% //循环输出货物 for (int i = 0; listGoodss != null && i < listGoodss.size(); i++) { Goods goods = (Goods)listGoodss.get(i); m++; %> <tr> <td><input type="checkbox" name="checkbox" value="<%=i%>"></td> <input type="hidden" name="goodsId<%=i%>" width="320" value="<%=goods.getId()%>"> <td ><input type="text" name="name<%=i%>" value="<%=goods.getName()%>"></td> <td ><input type="text" name="price<%=i%>" value="<%=goods.getPrice()%>"></td> <td ><input type="text" name="count<%=i%>" value="<%=goods.getCount()%>"></td> <td ><select name="goodsTypeId<%=i%>"> <% for (int j = 0; listGoodsTypes != null && j < listGoodsTypes.size(); j++) { GoodsType goodsType = (GoodsType)listGoodsTypes.get(j); %> <option value="<%=goodsType.getId()%>" <%= goodsType.getId()==goods.getGoodsType().getId() ? "selected" : ""%>><%=goodsType.getName()%></option> <%}%> </select> </td> <td><input type="text" name="releaseDate<%=i%>" value="<%=goods.getReleaseDate()%>"></td> </tr> <% } %> <!--始终保持一个空行以供输入--> <tr> <td><input type="checkbox" name="checkbox" value="<%=m%>"></td> <td ><input type="text" name="name<%=m%>" value=""></td> <td ><input type="text" name="price<%=m%>" value=""></td> <td ><input type="text" name="count<%=m%>" value=""></td> <td ><select name="goodsTypeId<%=m%>"> <% for (int j = 0; listGoodsTypes != null && j < listGoodsTypes.size(); j++) { GoodsType goodsType = (GoodsType)listGoodsTypes.get(j); %> <option value="<%=goodsType.getId()%>" ><%=goodsType.getName()%></option> <%}%> </select> </td> <td><input type="text" name="releaseDate<%=m%>" value=""></td> </tr> <tr> <td colspan="6"><div align="center"></div> <div align="center"> <input type="button" name="create" value="新增" onClick="return check('create')"> <input type="button" name="update" value="修改" onClick="return check('update')"> <input type="button" name="delete" value="删除" onClick="return check('delete')"> </div></td> </tr> </table> </form> <script language=Javascript> function check(action) { document.forms[0].action = "goodsAction!" + action + ".action"; document.forms[0].submit(); } </script> </body> </html>
那goodsIdxxx到底是那个啊?
问题补充:
missoasis 写道
引用
hh=req.getParameter("goodsId" + (String)req.getParameter("checkbox") + "")
提取的jsp中 goodsIdxxx+空格 元素的值吗(假如(String)req.getParameter("checkbox") 返回的是xxx)。
现在就有另外一个问题了 jsp中的checkbox元素类型是checkbox,那返回的是什么啊。
还有jsp页面中没有 goodsIdxxx+空格 这个元素 :
注:我看的书《我的J2EE成功之路》 郭峰 著作 电子工业出版社
提取的jsp中 goodsIdxxx+空格 元素的值吗(假如(String)req.getParameter("checkbox") 返回的是xxx)。
现在就有另外一个问题了 jsp中的checkbox元素类型是checkbox,那返回的是什么啊。
还有jsp页面中没有 goodsIdxxx+空格 这个元素 :
注:我看的书《我的J2EE成功之路》 郭峰 著作 电子工业出版社
这本书我没看过,但是
(String)req.getParameter("checkbox") 返回的是xxx 这句取得是一个name属性为checkbox的元素,而不是checkbox复选款的值,因为checkbox是复选款,所有可能会有几个这样的东西<input type="checkbox" name="a">,要取checkbox复选框的值,那么后台应该这样写:req.getParameters("a");返回的是一个数组,数组就是复选框各个选项的值;
"goodsId" + (String)req.getParameter("checkbox") + "",是字符串相加,""是空字符,而不是空格,提取的jsp中 goodsIdxxx的值
谢谢了 看了好久终于明白了
<
td ><input type="text" name="count<%=m%>" value=""></td>
中的 "count<%=m%>" 是个字符串 <%=m%> 是个函数返回的也是字符串
再请问下 您觉得我要在学习 javaweb 的话 现在最需要把那学地方搞懂
(您对我的评价就参照我我所提的问题就可以了) 我是自学的 所以还想请您推荐一下一些好书、
相关问答
更多-
我需要一段最简单的java代码程序[2022-02-06]
public class HelloWorld{ public static void main(String[] args){ System.out.println("hello world!"); } } 一. 基本概念 Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。 二. 体系 Java分为三个体系,分别为Java SE( ... -
Java一段简单的代码,最好带上讲解~本人菜鸟[2022-08-07]
public static int sumSome(int position,int max){ int params[] = new int[]{4,3,5,8,5,3,1,5,1,8,0,6}; //读入的一串整数 int total = 0; //总和 for (int i = 0; i < params.length; i++) { if((i+1)%position == 0){ //如果能整除postion,因为数组是从0开始,所以要加1 total += params[i]; } } retu ... -
求一段ajax代码[2023-05-08]
无耐!我也在寻找相关的代码!Ajax搞得真是太神秘了! -
java:求一段代码,很简单,运行后直接播放一个小视频,播放完后(或者自行定时)立刻自动关闭。[2023-10-19]
下载JMF(java media framework) 下面是一个例子 import java.awt.BorderLayout; import java.awt.Component; import java.net.MalformedURLException; import java.net.URL; import javax.media.Manager; import javax.media.MediaLocator; import javax.media.Player; import javax.sw ... -
python 文件拷贝.简单的一段代码.[2023-08-01]
import shutil shutil.copy("file1", "file2") -
python给一段代码加上for循环[2019-05-11]
定界符倒只有空格 不过你可以试试选中所有要缩进的代码 然后按TAB键 就能一次性缩进所有代码,大部分编辑器支持这个功能 -
求一段JAVA代码[2022-02-22]
Image getImage(String filename){ URLClassLoader urlLoader=(URLClassLoader)this.getClass(). getClassLoader(); URL url=null; Image image=null; url=urlLoader.findResource(filename); image=Toolkit.getDefaultToolkit().getImage(url); MediaTracker mediatracker=ne ...