<jsp:getproperty sample1BeanId" property="sample"/>
或者
<%=sample1BeanId.getSample()%>注意要“()”
直接这样就可以取道提交后得属性
或者
<%=sample1BeanId.getSample()%>注意要“()”
直接这样就可以取道提交后得属性
解决方案 »
- 如何记录登陆前的最后位置啊
- org.hibernate.exception.GenericJDBCException: could not insert
- 请大家帮帮我,从数据库中直接读图片显示到页面,后台数据和前台页面不同步的问题.
- java实现数据库端分页
- 公司需要开发一个大网站,有一些问题想问问大家
- 求正则表达式
- Action的execetu()返回的错误怎么在jsp上显示啊?是不是也用ActionErrors?
- 在jsp中怎么用代码实现对table的id值的获取???
- 请假用response.sendRedirect传递中文参数的问题?
- jsp新手请教
- 关于final
- 多个弹出窗口同时打开问题(帮看看我的代码)
String fzno = (String)request.getParameter("fzno").trim();
这句应该不会报错吧最好先用个if来判断一下传过来的数据是否为空
request.getParameter("");返回的本来就是String
楼主是怎么提交的??
谢谢大家的支持,请注意我这主要是在本页取本页表单的数据,取过来就报错
先用个IF过滤掉吧
先判断submit的值,然后再做处理。
还有,把你的代码贴上来看看,这样说不明白!
String fzno = request.getParameter("fzno")==null?"":request.getParameter("fzno").trim();
这个没有错
String fzno = request.getParameter("fzno").trim();
这个有问题
想想看,如果request.getParameter("fzno")得到的是一个null或者"" trim肯定出错
你应该这样处理:
String fzno_tmp = request.getParameter("fzno");
if (null != fzno_tmp && !"".equals(fzno_tmp))
String fzno = fzno_tmp.trim();
先判断submit的值,然后再做处理。
<%@ page import="com.xph.Login" %>
<%! //处理字符串的方法:
public String codeString(String s)
{ String str=s;
try{byte b[]=str.getBytes("ISO-8859-1");
str=new String(b);
return str;
}
catch(Exception e)
{ return str;
}
}
%>
<HTML>
<BODY>
<%String string=response.encodeURL("userLogin.jsp");
%>
<P align="center"><br>
<br>
<br>
<br>
输入用户名和密码:
<FORM action="<%=string%>" Method="post">
<div align="center"><BR>
登录名称
<Input type=text name="name">
<BR>
输入密码
<Input type=password name="password">
<BR><br><br>
<Input type=submit name="g" value="提交">
</div>
</Form>
<jsp:useBean id="login" class="com.xph.Login" scope="session" >
</jsp:useBean>
<% //提交信息后,验证信息是否正确:
String message="",password="",name="";
if(!(session.isNew()))
{name=request.getParameter("name");
if(name==null)
{name="";
}
name=codeString(name);
password=request.getParameter("password");
if(password==null)
{password="";
}
password=codeString(password);
}
%>
<%
if(!(name.equals("")))
{
%>
<jsp:setProperty name= "login" property="name" value="<%=name%>" />
<jsp:setProperty name= "login" property="password" value="<%=password%>" />
<%
message=login.getMessage();
if(message==null)
{message="";}
}
%>
<% if(!(session.isNew()))
{ if(message.equals("ok"))
{
if(login.getQx().equals("1"))
{response.sendRedirect("index.htm");}
else if(login.getQx().equals("2"))
{response.sendRedirect("run.jsp");}
else if(login.getQx().equals("3"))
{response.sendRedirect("yxchaxun.jsp");}
//String str=response.encodeURL("run.jsp");
//response.sendRedirect(str);
}
else
{out.print(message);
}
}
%>
</Body>
</HTML>
我这个本页传值是好的啊,我想可能程序有流程的问题,因为代码被容器解释了之后就生成.class文件,执行的时候就是顺序执行下来的,先写出表单,再写出request看看会不会好。
String fzno = (String)request.getParameter("fzno");
如果request.getParameter("fzno")的值为空,就会出现异常,最好是像这样:
String fzno = null;
if(request.getParameter("fzno") != null) {
fzno = request.getParameter("fzno").trim();
}