关于tomcat404的解决方案 网上的方法都试过了 还是没用

package myservlet;

import java.io.IOException;
import javax.servlet.ServletConfig;
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 mybean.*;
import java.sql.*;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
/**

  • Servlet implementation class HandleRegister
    */
    @WebServlet("/HandleRegister")
    public class HandleRegister extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**

    • @see HttpServlet#HttpServlet() */ public HandleRegister() { super(); // TODO Auto-generated constructor stub }

    /**

    • @see Servlet#init(ServletConfig) / public void init(ServletConfig config) throws ServletException { // TODO Auto-generated method stub super.init(config); //加载jdbc数据库驱动程序 try { Class.forName("com.mysql.jdbc.Driver"); } catch(Exception e) {} } /*
    • @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      request.setCharacterEncoding("UTF-8");
      response.setContentType("text/html;charset=UTF-8");
      response.setCharacterEncoding("UTF-8");
      Connection con;
      PreparedStatement sql;
      Register reg=new Register();
      request.setAttribute("register", reg);
      String logname=request.getParameter("logname").trim(),
      password=request.getParameter("password").trim(),
      email=request.getParameter("email").trim();
      if(logname==null)
      logname="";
      if(password==null)
      password="";
      if(email==null)
      email="";
      boolean isLD=true;

      boolean boo=logname.length()>0&&password.length()>0&&isLD;
      String backNews="";
      try {
      String uri="jdbc:mysql://localhost:3306/test?"+
      "user=root&password=pader&charset=UTF-8";
      //建立与指定数据库test的连接对象con
      con=DriverManager.getConnection(uri);
      String insertCondition="INSERT INTO member VALUES(?,?,?)";
      //利用con对象调用preparstatement方法生成执行sql语句对象
      sql=con.prepareStatement(insertCondition);
      if(boo) {
      sql.setString(1, logname);//利用sql对象调用set方法设置?代表的具体值
      sql.setString(2, password);
      sql.setString(3, email);
      //数据库操作对象sql调用executeupdate()方法并返回成功的记录条数
      int m=sql.executeUpdate();
      if(m!=0)
      {
      backNews="注册成功";reg.setBackNews(backNews);reg.setLogname(logname);reg.setPassword(password);reg.setEmail(email);
      }
      }
      else {backNews="信息不完整或名字中存在非法字符"; reg.setBackNews(backNews);}
      //释放资源
      sql.close();
      con.close();
      }
      catch(SQLException exp) {
      backNews="该名字已被使用,请您更换名字"+exp;
      reg.setBackNews(backNews);
      }
      RequestDispatcher dispatcher=request.getRequestDispatcher("show.jsp");//转发
      dispatcher.forward(request, response);
      }

    /**

    • @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }图片说明

5个回答

兄弟,用中文目录啊,浏览器自动将其转码,你看到的massage里面就是实际传到后台的地址

你在那里边跳的这个页面啊????还是直接访问的这个页面?

tomcat能访问吗

服务端报了什么错没?
看看是否是端口配置错了,Get/Postmapping是否有错,register.jsp是否放在正确的位置,一个个排除看看

考虑是不是中文项目名称,被自动转码了,识别不了

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问