Myeclipse简单的注册界面跳转Servlet空白页面或者请求的资源[/chapter2/register.html]不可用

小白,学习记录一下憋了一个晚上的问题,最后都记录下吧

解决方法在文章最后

目录

解决方法

遇见的问题截图

以为是这个查了不是

 后来卡在这里了,一直以为是不是我代码有问题,或者数据库没连接上,是不是连接数据库代码有问题,然后反复纠结,网上查,什么buildpath mysql-connector-java-3.0.11-stable-bin.jar包没导好,也按照网上建立数据库也不行。

最后发现确实是没链接上(笑哭)jar包放错位置了......

 

部分代码,最后是没问题的

register.html

<!DOCTYPE html>
<html>
  <head>
    <title>register.html</title>
	
    <meta name="keywords" content="keyword1,keyword2,keyword3">
    <meta name="description" content="this is my page">
    <meta name="content-type" content="text/html; charset=UTF-8">
    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

  </head>
  
  <body>
  
  register
    <form name="f1" id="f1" action="servlet/LoginServlet" method="post">
      <table>
        <tr>
          <td>name:</td>
          <td><input type="text" name="username" id="login"></td>
        </tr>
        <tr>
          <td>Password:</td>
          <td><input type="password" name="userpassword" id="password"></td>
        </tr> 
        <tr>
          <td colspan="2"><input type="submit" value="register"></td>
        </tr>
      </table>
    </form>
  </body>
</html>

LoginServlet.java

package userinfo;

import java.io.IOException;
import java.io.PrintWriter;

//import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public LoginServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");
		out.print("    This is ");
		out.print(this.getClass());
		out.println(", using the GET method");
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");
		
		//RequestDispatcher dis=request.getRequestDispatcher("../handleLogin.jsp");
		//RequestDispatcher dis=request.getRequestDispatcher("http://www.dlou.edu.cn");
		//dis.forward(request, response);

		String name=request.getParameter("username");
		
		String password=request.getParameter("userpassword");

		FirstJavaBean fj=new FirstJavaBean();
		//boolean result=fj.verifyLogin(name, password);
		boolean result=fj.register(name, password);
		if(result)
			
			out.println("  successful!");
		else
			out.println("failure!");
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

解决方法

 

 那个jar包我是放到 tomcat/lib 下了

千万别跟着项目,然后放到 WEB-INF/lib 下*****************

最后windows那个图片的 

然后右键你的库我的是Connect

Add JARs把你刚才在tomcat/lib下的jar包导进来,把原来的remove掉就好了。

 舒服了~

最后在解释下那个为啥不能放WEB-INF/lib下,因为在myeclipse中,如果把jsp啥的写在WEB-INF下的话,将受到访问保护,需要配置web.xml来访问。

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

海大小杰

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值