lisuixin256 2022-02-18 23:57 采纳率: 33.3%
浏览 76

ajax跳转页面404

img


register.jsp代码:


<%@ page language="java"  contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>

<html>
<head>
<title>注册</title>
<script  type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  <script>
    function getBasePath(){
        return '<%=basePath%>';
    }
  </script>

</head>
<center>
<body style="width:100%">
<style>
.tes{font-size:26px;}
.mtd{text-align:center;vertical-align:middle;}
.mtd1{text-align:left;vertical-align:middle;}
.behind{color:#737373;font-size:24px;}
</style>
<form name="register">
<div style="width:100%;height:500px;">
<img src="./image/register.png"style="width:100%;height:100%;object-fit:cover"/>
</div>
<div style="background-color:#e5f7ff;width:100%;height:1300px;">
<div style="background-color:rgba(255,255,255,0.5);width:1200px;height:1300px;">
<table  style="position:absolute;top:600px;left:40%">
<tr style="height:90px;">
<td class="tes mtd">手机号码:</td>
<td class="mtd1 tes behind"><input  type="text" id="n1" name="number" style="height:35px;width:250px;"/>
<input name="phonetest" type="bottom" id="but1"  value="获取验证码" onclick="stepping()" style="height:32px;width:85px;background-color:#80ff00;border:1px solid #2eb82e" readOnly>
</td>
</tr>

<script type="text/javascript">
function stepping(){
var number=document.register.number.value;
var but1 = document.getElementById("but1"); //获取要改变颜色的id
but1.style.backgroundColor="#bfbfbf";
but1.style.disable="disable";
 setTimeout(function () { but1.style.disable="";but1.style.backgroundColor="#80ff00"}, 1000*60*3);

$.ajax({
            url: getBasePath()+"/sendSms1.java",

            async : true,
            type: "post",
            dataType: "json",
            data: {"number":number},
            success: function (data) {
                if(data == 'fail'){
                    alert("发送验证码失败");

                }
                else if(data=='success')
                {alert("发送验证码成功");}
                return ;
            }
        });
}
</script>
<tr style="height:90px;">
<td class="tes mtd">验证码:</td><td class="mtd1 tes behind"><input  type="text" name="name" style="height:35px;width:120px;"/></td>
</tr>
</table>
<input align="center" type="submit" value="提交" style="font-size:22px;position:absolute;top:1550px;width:100px;height:35px;background-color:#0099e6;border:2px solid #0088cc;"/>
</div>
</div>
</form>
</body>
</center>
</html>

sendSms1.java代码:

import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class sendSms1 {
    @RequestMapping(value="/sendSms1")
    @ResponseBody
    public Object sendSms(HttpServletRequest request, String number) {
        try {
            JSONObject json = null;
            //生成6位验证码
            String verifyCode = String.valueOf(new Random().nextInt(899999) + 100000);
            //发送短信
            ZhenziSmsClient client = new ZhenziSmsClient("https://sms_developer.zhenzikj.com","110932","cff55be5-fc70-454e-8311-2c20b33fd5d9");
            Map<String, Object> params = new HashMap<String, Object>();
            params.put("number", number);
            params.put("templateId", "8212");
            String[] templateParams = new String[2];
            templateParams[0] = verifyCode;
            templateParams[1] = "3分钟";
            params.put("templateParams", templateParams);
            String result = client.send(params);
            json = JSONObject.parseObject(result);
            if(json.getIntValue("code") != 0)//发送短信失败
                return "fail";
            //将验证码存到session中,同时存入创建时间
            //以json存放,这里使用的是阿里的fastjson
            HttpSession session = request.getSession();
            json = new JSONObject();
            json.put("verifyCode", verifyCode);
            json.put("createTime", System.currentTimeMillis());
            // 将认证码存入SESSION
            request.getSession().setAttribute("verifyCode", json);
            return "success";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}


补充:pom.xml代码

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>sp2</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>sp2 Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
    <dependencies>
        <dependency>
            <groupId>io.leopard.boot</groupId>
            <artifactId>leopard-boot-requestmapping</artifactId>
            <version>0.9.20</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>5.3.10</version>
        </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>5.3.10</version>
      </dependency>
    </dependencies>


    <build>
    <finalName>sp2</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>

      </plugins>
    </pluginManagement>
  </build>
</project>


帮我看看吧,网上查了好多都没解决,非常感谢!!

  • 写回答

2条回答 默认 最新

  • 涤生啊 2022-02-19 00:11
    关注

    img

    img


    请求改为一致试试?

    评论

报告相同问题?

问题事件

  • 修改了问题 2月19日
  • 创建了问题 2月18日

悬赏问题

  • ¥15 想用adb命令做一个通话软件,播放录音
  • ¥30 Pytorch深度学习服务器跑不通问题解决?
  • ¥15 部分客户订单定位有误的问题
  • ¥15 如何在maya程序中利用python编写领子和褶裥的模型的方法
  • ¥15 Linux权限管理相关操作(求解答)
  • ¥15 Bug traq 数据包 大概什么价
  • ¥15 在anaconda上pytorch和paddle paddle下载报错
  • ¥25 自动填写QQ腾讯文档收集表
  • ¥15 DbVisualizer Pro 12.0.7 sql commander光标错位 显示位置与实际不符
  • ¥15 android 打包报错