StringUtil.java
public class StringUtil {
public StringUtil(){}
private String name;
private String pwd;
private String cue;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getCue() {
if((name==null||name.equals(""))||(pwd==null||pwd.equals(""))){
cue="请输入用户名或密码!";
}else{
if(name.equals("admin")&&pwd.equals("123456")){
cue="登录成功!";
}else {
cue="登录失败!<b>用户名</b>或<b>密码</b>不正确!";
}
}
return cue;
}
public void setCue(String cue) {
this.cue = cue;
}
}
index.jsp
<form action="result.jsp" method="post">
<table>
<tr>
<td align="right">请输入用户名:</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td align="right">请输入密码:</td>
<td><input type="password" name="pwd" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="登录"/></td>
</tr>
</table>
</form>
result.jsp
<%
request.setCharacterEncoding("utf-8");
String name= request.getParameter("name");
String pwd = request.getParameter("pwd");
%>
<jsp:useBean id="strBean" class="com.count.StringUtil"></jsp:useBean>
<jsp:setProperty property="name" name="strBean" value="<%=name %>"/>
<jsp:setProperty property="pwd" name="strBean" value="<%=pwd %>"/>
<table>
<tr>
<td align="right">提示信息:</td>
<td>
<jsp:getProperty property="cue" name="strBean"/>
</td>
</tr>
<tr>
<td align="center" colspan="2"><a href="index.jsp">【返回】</a></td>
</tr>
</table>
16.PNG
网友评论