dimanche 29 juillet 2018

second time submit form with info changed but the action in server didnt get the request

just a login html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>测试的登录页面</title>
<link href="css/mui.min.css" rel="stylesheet" />
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">

</head>
<body>
<header class="mui-bar mui-bar-nav">
            <h1 class="mui-title">登录</h1>
</header>
        <div class="mui-content">
            <form id='login-form' class="mui-input-group" action="/front/login">
                <div class="mui-input-row" style="padding-right: 14px;">                
                    <input name="phone" type="text" style="width: 66%;" class="mui-input-clear mui-input" placeholder="请输入你的手机号">                           
                </div>      
            <div class="mui-content-padded">
                <button id='login' class="mui-btn mui-btn-block mui-btn-primary" type="submit" >登录</NOtton>     
            </div>
            </form>
        </div>

        <script src="js/mui.min.js"></script>
</body>
</html>

the action is here

    package com.neu.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


import com.neu.beans.Userlist;
import com.neu.service.FrontCheckService;



@Controller
public class FrontLoginHandler {
    @Autowired
    private  FrontCheckService service;

      @RequestMapping(value = "/front/login")   
      public  String frontlogin(HttpServletRequest request,HttpServletResponse response)
      {
          //请求和响应的信息都不应该被存储在对方的磁盘系统中; 

          System.out.println("....servlet....frontlogin()......");
         System.out.println("....servlet....frontlogin()......");
        System.out.println("....servlet....frontlogin()......");
        System.out.println("....servlet....frontlogin()......");
        System.out.println("....servlet....frontlogin()......");
         //从数据库查找是否存在这样一个手机号的用户
          //如果存在那么就取出来 返回
          //如果不存在那么就 写入一个
          String phone=request.getParameter("phone");       
          if(service.check(phone)==null)
          {
              Userlist user=new Userlist();
              user.setTel(phone);       
              user.setUname(phone);
             user.setOpenid(phone);
              user.setUserimg("default.jpg");
              adduser(user);
             System.out.println(user.getTel());
             HttpSession session=request.getSession();
             session.setAttribute("user", user);
             System.out.println("存入session成功!");
             return "forward:index.html";
              //如果为空 捏造一个用户 返回 并 写入数据库
          }
          else
          {
             Userlist user= service.check(phone);
             System.out.println(user.getTel());
            HttpSession session=request.getSession();            
             session.setAttribute("user", user);
             System.out.println("存入session成功!");
            return "forward:index.html";
              //如果不为空 那就将返回的对象返回
          }


      }

      public  void adduser(Userlist user)
      {
          String phone= user.getTel();
          service.insert(phone);          
      }

}

the question is that when i first time input a phone number ,login successful,and get the right username . and when i surf the page again ,submit with another phonenumber its ok .but the third time with another phone number login the user name is name before. i check the eclipse console find the third time request didnt send to the action,because the several "System.out.println()" didnt printed. the get name page is a page with ajax to get another action to return the "user" attribute of session.




Aucun commentaire:

Enregistrer un commentaire