当前位置:编程学习 > JAVA >>

J2EE学习笔记——Struts2多方法实现

 

 

\


实现  登陆 验证 和注册 验证在一个  LoginAction  类中:

 


Login.jsp:


[html]  <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 
<%@ taglib uri="/struts-tags" prefix="s" %> 
 
<% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
    <base href="<%=basePath%>"> 
     
    <title>Login</title> 
    <meta http-equiv="pragma" content="no-cache"> 
    <meta http-equiv="cache-control" content="no-cache"> 
    <meta http-equiv="expires" content="0">     
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="This is my page"> 
 
  </head> 
   
  <body> 
     
     <s:form  action="loginAction" method="post"> 
      
        <s:textfield  name="username" label="用户名" /> <br> 
         
         <s:password name="password"  label="密码"/> <br> 
          
           <input type="submit" value="登陆"> <br> 
      
     </s:form> 
     
     
  </body> 
</html> 

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>Login</title>
 <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">   
 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
 <meta http-equiv="description" content="This is my page">

  </head>
 
  <body>
   
     <s:form  action="loginAction" method="post">
    
        <s:textfield  name="username" label="用户名" /> <br>
       
         <s:password name="password"  label="密码"/> <br>
        
           <input type="submit" value="登陆"> <br>
    
     </s:form>
   
   
  </body>
</html>

 


Reg.jsp:


[html] <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%@ taglib uri="/struts-tags" prefix="s" %> 
<% 
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
    <base href="<%=basePath%>"> 
     
    <title>My JSP 'reg.jsp' starting page</title> 
     
    <meta http-equiv="pragma" content="no-cache"> 
    <meta http-equiv="cache-control" content="no-cache"> 
    <meta http-equiv="expires" content="0">     
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="This is my page"> 
     
 
  </head> 
   
  <body> 
      <s:form  action="regAction" method="post"> 
      
        <s:textfield  name="username" label="用户名" /> <br> 
         
         <s:password name="password"  label="密码"/> <br> 
          
           <input type="submit" value="注册"> <br> 
      
     </s:form> 
  </body> 
</html> 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'reg.jsp' starting page</title&g

补充:软件开发 , Java ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,