解决方案 »
- 弹出窗口中的iframe如何给父窗口赋值?
- <forward name="fail" path="/login.jsp"> 这个login.jsp是登陆页面 可是这是iframe右边的
- js文件导入分前后顺序?
- 如何计算页面占用流量
- STRUTS连接的是ORACLE数据库的问题
- 不知道为何,请高手指点
- Struts里forward到一个新的页面怎样指定它出现的框架
- 一个上传文件的问题,up有分.分不够再加
- 想修改源程序,可不知道保存在什么地方的时候怎么办?
- 谁能告诉我,LONG类型怎么转化成DATE类型输出显示啊,困扰我好久的问题了!
- 大神都帮忙看看!简直醉了!!!
- spring jdbc中一段代码不太理解
实在想写,用这样
<%
out.println("<input type=‘text’ name=‘userName’>");
%>
然后点击这个input所在form的按钮是能提交到,相应的servlet中的
我的意思是他的页面有<input name="userName" > 表单提交到servlet的时候,servlet可以根据input文本框name属性为userName获取值request.getParameter("userName");
试了下,貌似还是不行。
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"'>OK</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=cancel'>Cancel</a></td>");
}
out.println("</tr>");
}
%>
就是想实现edit,然后点OK,到servlet中取不到text中的cname和cphone
我的意思是他的页面有<input name="userName" > 表单提交到servlet的时候,servlet可以根据input文本框name属性为userName获取值request.getParameter("userName");
是啊,问题是你写的代码值是空字符串啊,得到的也是空字符串,难道是 null? 如果是null说明你提交的表单中没有userName字段域
试了下,貌似还是不行。
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"'>OK</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=cancel'>Cancel</a></td>");
}
out.println("</tr>");
}
%>
就是想实现edit,然后点OK,到servlet中取不到text中的cname和cphoneout.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"&cname="+cus.getName()+"&cphone="+cus.getPhone()+"'>OK</a>");
那要怎么获取。。我写个简单的例子
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
上面这段代码是web项目jsp页面都有的,就是获取项目路径的脚本,不需要自己写的。
<form method="post" action="<%=basePath%>/requestServlet"> 就好了。
这里的requestServlet是servlet的名字。
试了下,貌似还是不行。
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"'>OK</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=cancel'>Cancel</a></td>");
}
out.println("</tr>");
}
%>
就是想实现edit,然后点OK,到servlet中取不到text中的cname和cphoneout.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"&cname="+cus.getName()+"&cphone="+cus.getPhone()+"'>OK</a>");
那样是传了本来的值了,现在是edit功能,就是修改cus.name和cus.phone
我的意思是他的页面有<input name="userName" > 表单提交到servlet的时候,servlet可以根据input文本框name属性为userName获取值request.getParameter("userName");
是啊,问题是你写的代码值是空字符串啊,得到的也是空字符串,难道是 null? 如果是null说明你提交的表单中没有userName字段域
我的搞不清,你是回答者还是提问者了,如果不填文本框userName的值,页面给个提示不就好了,不能为空。
一般如果需要存入东西到数据库就不能为空了,所以做程序可以控制这个,必须的输入值啊。
不正规的话,假如不输入值,我在servlet做个非空的判断不就好了,
servlet:
String userName = request.getParameter("userName");
if(userName!= null &&userName != ""){
}
我的意思是他的页面有<input name="userName" > 表单提交到servlet的时候,servlet可以根据input文本框name属性为userName获取值request.getParameter("userName");
是啊,问题是你写的代码值是空字符串啊,得到的也是空字符串,难道是 null? 如果是null说明你提交的表单中没有userName字段域一般页面要输入的字段是(数据库)不能为空的字段,如果不输入就提交表单了,那我想你这个程序做了也没有什么意义了。
那要怎么获取。。我写个简单的例子
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
上面这段代码是web项目jsp页面都有的,就是获取项目路径的脚本,不需要自己写的。
<form method="post" action="<%=basePath%>/requestServlet"> 就好了。
这里的requestServlet是servlet的名字。先谢谢你!首先原谅我不是很懂为什么要这样写,然后我这样改了还是没有效果,控制台输出的接收值还是null。。
试了下,貌似还是不行。
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"'>OK</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=cancel'>Cancel</a></td>");
}
out.println("</tr>");
}
%>
就是想实现edit,然后点OK,到servlet中取不到text中的cname和cphoneout.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"&cname="+cus.getName()+"&cphone="+cus.getPhone()+"'>OK</a>");
那样是传了本来的值了,现在是edit功能,就是修改cus.name和cus.phone
你还是老老实实写post 表单吧
<form name="form1" action="Ex6_2Servlet.do" method="post">
<input type="hidden" name="opttype" value="ok" />
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='javascript:void(0)' onlclick="document.forms[0].opttype='edit';document.forms[0].submit()">OK</a>");
out.println("<a href='javascript:void(0)' onlclick="document.forms[0].opttype='cancel';document.forms[0].submit()">Cancel</a></td>");
}
out.println("</tr>");
}
%>
那要怎么获取。。我写个简单的例子
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
上面这段代码是web项目jsp页面都有的,就是获取项目路径的脚本,不需要自己写的。
<form method="post" action="<%=basePath%>/requestServlet"> 就好了。
这里的requestServlet是servlet的名字。先谢谢你!首先原谅我不是很懂为什么要这样写,然后我这样改了还是没有效果,控制台输出的接收值还是null。。我表单提交的方式的post哦,那么就调用servlet的doPost()方法哦,不是调doGet方法哦。你发你的servlet文件和jsp页面给我看下,我就知道了。按我说的那种肯定可以传值的
试了下,貌似还是不行。
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"'>OK</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=cancel'>Cancel</a></td>");
}
out.println("</tr>");
}
%>
就是想实现edit,然后点OK,到servlet中取不到text中的cname和cphoneout.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"&cname="+cus.getName()+"&cphone="+cus.getPhone()+"'>OK</a>");
那样是传了本来的值了,现在是edit功能,就是修改cus.name和cus.phone
你还是老老实实写post 表单吧
<form name="form1" action="Ex6_2Servlet.do" method="post">
<input type="hidden" name="opttype" value="ok" />
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='javascript:void(0)' onlclick="document.forms[0].opttype='edit';document.forms[0].submit()">OK</a>");
out.println("<a href='javascript:void(0)' onlclick="document.forms[0].opttype='cancel';document.forms[0].submit()">Cancel</a></td>");
}
out.println("</tr>");
}
%>
不好意思,图书馆10点关门,赶紧回宿舍看的,意思我大概明白了,但是onClick后面的“和前面的println的”匹配了,编译错误了,换成单引号后网页源代码就这样了
<td><a href='javascript:void(0)' onlclick='document.forms[0].opttype='ok';document.forms[0].submit()'>OK</a>
这样也肯定不行,那单引号又和ok前面的单引号匹配了。。servlet连opttype为ok都接收不到了
试了下,貌似还是不行。
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"'>OK</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=cancel'>Cancel</a></td>");
}
out.println("</tr>");
}
%>
就是想实现edit,然后点OK,到servlet中取不到text中的cname和cphoneout.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"&cname="+cus.getName()+"&cphone="+cus.getPhone()+"'>OK</a>");
那样是传了本来的值了,现在是edit功能,就是修改cus.name和cus.phone
你还是老老实实写post 表单吧
<form name="form1" action="Ex6_2Servlet.do" method="post">
<input type="hidden" name="opttype" value="ok" />
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='javascript:void(0)' onlclick="document.forms[0].opttype='edit';document.forms[0].submit()">OK</a>");
out.println("<a href='javascript:void(0)' onlclick="document.forms[0].opttype='cancel';document.forms[0].submit()">Cancel</a></td>");
}
out.println("</tr>");
}
%>
不好意思,图书馆10点关门,赶紧回宿舍看的,意思我大概明白了,但是onClick后面的“和前面的println的”匹配了,编译错误了,换成单引号后网页源代码就这样了
<td><a href='javascript:void(0)' onlclick='document.forms[0].opttype='ok';document.forms[0].submit()'>OK</a>
这样也肯定不行,那单引号又和ok前面的单引号匹配了。。servlet连opttype为ok都接收不到了
语句是我随便写的,看重点,重点是你要提交表单。
帅哥,整个页面都没有看到你表单提交,你servlet会取得到值吗????整个jsp页面就看到你这个地方用了超链接,也只是传了一个opttype的值。
servlet永远输出为null.原因是你没有提交过去。好吧,我测试了下,原来到最后我问的问题都是错的。。java学习任重道远啊。。感谢各位
试了下,貌似还是不行。
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"'>OK</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=cancel'>Cancel</a></td>");
}
out.println("</tr>");
}
%>
就是想实现edit,然后点OK,到servlet中取不到text中的cname和cphoneout.println("<td><a href='Ex6_2Servlet.do?opttype=ok&cid="+cus.getCustomerID()+"&cname="+cus.getName()+"&cphone="+cus.getPhone()+"'>OK</a>");
那样是传了本来的值了,现在是edit功能,就是修改cus.name和cus.phone
你还是老老实实写post 表单吧
<form name="form1" action="Ex6_2Servlet.do" method="post">
<input type="hidden" name="opttype" value="ok" />
<%
for(customer cus:clist){
out.println("<tr>");
if(!cus.getCustomerID().equals(session.getAttribute("editid"))){
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td>"+cus.getName()+"</td>");
out.println("<td>"+cus.getPhone()+"</td>");
out.println("<td><a href='Ex6_2Servlet.do?opttype=delete&cid="+cus.getCustomerID()+"'>Delete</a>");
out.println("<a href='Ex6_2Servlet.do?opttype=edit&cid="+cus.getCustomerID()+"'>Edit</a></td>");
}else{
out.println("<input type=hidden name=cid value='"+cus.getCustomerID()+"' >");
out.println("<td>"+cus.getCustomerID()+"</td>");
out.println("<td><input type='text' name='cname' value="+cus.getName()+"></td>");
out.println("<td><input type='text' name='cphone' value="+cus.getPhone()+"></td>");
out.println("<td><a href='javascript:void(0)' onlclick="document.forms[0].opttype='edit';document.forms[0].submit()">OK</a>");
out.println("<a href='javascript:void(0)' onlclick="document.forms[0].opttype='cancel';document.forms[0].submit()">Cancel</a></td>");
}
out.println("</tr>");
}
%>
不好意思,图书馆10点关门,赶紧回宿舍看的,意思我大概明白了,但是onClick后面的“和前面的println的”匹配了,编译错误了,换成单引号后网页源代码就这样了
<td><a href='javascript:void(0)' onlclick='document.forms[0].opttype='ok';document.forms[0].submit()'>OK</a>
这样也肯定不行,那单引号又和ok前面的单引号匹配了。。servlet连opttype为ok都接收不到了
语句是我随便写的,看重点,重点是你要提交表单。
嗯,我也明白了,我以为点链接到servlet也会有表单的值过去。。感谢