请教大佬,我这段代码哪里出错了?

从表单获取数据出错
index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>主页</title>

</head>

<body>

<form action="/Text/add" method="psot">

<table>

<td>

用户id:<input name="userId" value="" type="text">

</td>

<td>

用户名:<input name="userName" value="" type="text">

</td>

<td>

密码:<input name="userPassword" value="" type="text">

</td>

<td>

<input value="提交" type="submit">

</td>

</table>

</form>

</body>

</html>

servlet层

package com.text.servlet.user;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.text.entity.user;

/**

* Servlet implementation class add

*

*/

@WebServlet("/Text/add")

public class add extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

doGet(request, response);

//设置字符集

request.setCharacterEncoding("UTF-8");

response.setContentType("text/html;charset=utf-8");

String userId = request.getParameter("userId");

String username = request.getParameter("userName");

String psw = request.getParameter("userPassword");

//创建用户实体类

user u = new user(userId, username, psw);

//连接数据库

System.out.print(u);

//重定向;

if(true) {

response.sendRedirect("/index.jsp");

}else {

PrintWriter out = response.getWriter();

out.write("<script>");

out.write("alert('用户注册失败')");

out.write("location.href='https://segmentfault.com/q/1010000039111198/insert.jsp'");

out.write("<script>");

}

}

}

错误页面:
请教大佬,我这段代码哪里出错了?
项目目录:
请教大佬,我这段代码哪里出错了?

是不是index.jsp里面的method写错了,你写成了psot

post拼错了

回答

以上是 请教大佬,我这段代码哪里出错了? 的全部内容, 来源链接: utcz.com/a/109700.html

回到顶部