自定义标签类GetRequestParameterTag.java
package tags;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
public class GetRequestParameterTag extends TagSupport {
private String property;
public void setProperty(String property){
this.property = property;
}
public int doStartTag() throws JspException {
ServletRequest reg = pageContext.getRequest();
String value = reg.getParameter(property);
try{
pageContext.getOut().print(value == null ? "":value);
}catch(java.io.IOException e){
throw new JspException(e.getMessage());
}
return SKIP_BODY;
}
}
登陆成功welcome.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Welcome Page</title>
</head>
<body>
<jsp:userBean id="user" scope="session" class="beans.User"/>
<!--也可以
<%
User user = (User)session.getAttribute("user");
%>
-->
欢迎你:<font color=red><%=user.getUserName()%></font>
</body>
</html>
登陆失败loginFailed.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Login Failed</title>
</head>
<body>
<font color="#993366">请输入用户名和密码,或者创建一个新用户!</font>
<%@ include file="/login_form.jsp" %>
<hr>
<a href="<%=response.encodeURL("newAccount.jsp")%>">创建一个新用户 </a>
</body>
</html>
上一页 [1] [2] [3] [4] 下一页