环境:
IntellJ IDEA 2018.2.4
Tomcat8.5.34
JAVA1.80
引入依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>打开http://localhost:8080/d/
有表单可注册但是点击提交无反应。上面网址不会跳转http://localhost:8080/d/he
手动输入http://localhost:8080/d/hee?girl=q 有效 后台可显示部分内容
from表单尝试action多中方法 1.d/hee
2./hee
3.hee
都不可以 提交<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<from action="/d/he" method="post">
姓名:<input type="text" name="names"><br>
密码:<input type="text" name="pas">
<input type="submit" value="注册">
</from>
</body>
</html>
@WebServlet("/he")
public class RegisterServlet extends HttpServlet {
@Override //Get 请求
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String name1=req.getParameter("name");
String pas1=req.getParameter("pas");
System.out.println(name1+pas1);
System.out.println(req.getParameter("girl"));
} @Override //post 请求
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//转给doGet处理
doGet(req, resp);
}
}
[code=java]public class RegisterServlet extends HttpServlet {
@Override //Get 请求
protect
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.z.selevt.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/he</url-pattern>
</servlet-mapping>
</web-app>
IntellJ IDEA 2018.2.4
Tomcat8.5.34
JAVA1.80
引入依赖
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>打开http://localhost:8080/d/
有表单可注册但是点击提交无反应。上面网址不会跳转http://localhost:8080/d/he
手动输入http://localhost:8080/d/hee?girl=q 有效 后台可显示部分内容
from表单尝试action多中方法 1.d/hee
2./hee
3.hee
都不可以 提交<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<from action="/d/he" method="post">
姓名:<input type="text" name="names"><br>
密码:<input type="text" name="pas">
<input type="submit" value="注册">
</from>
</body>
</html>
@WebServlet("/he")
public class RegisterServlet extends HttpServlet {
@Override //Get 请求
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String name1=req.getParameter("name");
String pas1=req.getParameter("pas");
System.out.println(name1+pas1);
System.out.println(req.getParameter("girl"));
} @Override //post 请求
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//转给doGet处理
doGet(req, resp);
}
}
[code=java]public class RegisterServlet extends HttpServlet {
@Override //Get 请求
protect
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>com.z.selevt.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/he</url-pattern>
</servlet-mapping>
</web-app>
from表单尝试action多中方法 1.d/hee
2./hee
3.hee
都试过了
from表单尝试action多中方法 1.d/hee
2./hee
3.hee
都试过了
你多了个e,没看见吗
network如果是空的就刷新一下页面就能看到,然后点击一下注册,看点击的时候出现的那一条数据Request Url 是不是你后端的API地址
2./hee
3.heee 打多了
from表单尝试action多中方法 1.d/hee
2./hee
3.hee
都试过了
你多了个e,没看见吗尴尬尝试过太多。之前用hee , 都是改过的。实际上没有多个e。名字的对应的到的
from表单尝试action多中方法 1.d/he
2./he
3.he
我觉得是。但是不知道如何验证。 点击提交后。上面网址没有变化。 视频教学中会变化。再网页后面加上 xxx。然后根据web.xml 的映射关系。找到处理页面。进行处理
ajax 没学过。还不会。我这个是模仿自学视频中 写出来的代码。 我也试过站点用https://xxxx//xxx 直接制定。 和网址http://localhost:8080/d/he这样直接指。
自学视频中 操作步骤
刚入门还没用过postman。刚刚百度 下载 尝试了下
刚入门还没用过postman。刚刚百度 下载 尝试了下
被你搞蒙圈了,form表单提交都会跳转到action的地址去,你点击注册没跳过去,只有一个可能就是用JS阻止了表单的提交;
看下是不是按钮绑定了click事件用return false;或者form表单绑定了submit事件 return false;
我这里两个都配置的话是无法启动tomcat的,报错:Server Tomcat v7.0 Server at localhost failed to start.去掉web.xml,action直接写he就可以了
2. 密码 type 一般为password,当然你喜欢用text也没问题
刚入门还没用过postman。刚刚百度 下载 尝试了下
被你搞蒙圈了,form表单提交都会跳转到action的地址去,你点击注册没跳过去,只有一个可能就是用JS阻止了表单的提交;
看下是不是按钮绑定了click事件用return false;或者form表单绑定了submit事件 return false;
新手刚入门。百度查了下 JS阻止了表单的提交 click事件。 我项目代码里 这些代码都没有啊。 我就写了这些最基础的东西