• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
兔豚
博客园    首页    新随笔    联系   管理    订阅  订阅
2019.9.2课程设计情况

一、当天完成的任务

   今天开始搭服务器,我们使用eclipse配tomcat,然后Android studio来做客户端。今天先把tomcat给配置完了,然后eclipse中的tomcat遇到一些问题,出现了error,争取今天晚上解决。

 

  服务器端的代码:Login

复制代码
package com.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

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;

/**
 * Servlet implementation class LoginTest
 */
@WebServlet("/LoginTest")
public class Login extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Login() {
        super();
        // TODO Auto-generated constructor stub
    }
    public void init(ServletConfig config) throws ServletException {
        // TODO Auto-generated method stub
        super.init(config);
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        Connection con;
        Statement sql;
        String logname = request.getParameter("logname").trim();
        String password = request.getParameter("password").trim();
        String uri = "jdbc:mysql://localhost/MakeFriend";
        try {
            con = DriverManager.getConnection(uri,"root","201513010223");
            String condition = "select * from member where logname = '"+logname+"' and password = '"+password+"'";
            sql = con.prepareStatement(condition);
            ResultSet rSet = sql.executeQuery(condition);
            if(rSet.next()) {
                out.println("login successfully!");
            }
            else {
                out.println("can not login!");
            }
            con.close();        
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    /**
     * @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);
    }

}
复制代码

 

二、第二天的计划

   将tomcat和eclipse配置完成,将服务器搭建完成。

三、每日小结

1.当初J2EE学得忘得差不多了,现在搭服务器感觉很费劲。

2.感觉走进了死胡同,死在了服务器里。

posted on 2019-09-02 20:47  兔豚  阅读(153)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3