servletでselectしてredirect

Connection conn = null;
		ResultSet rs = null;
		
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection("jdbc:mysql://localhost/sampledb","root","");

			Statement stmt = conn.createStatement();
			String sql = "select * from userinfo where status = 2";
			rs = stmt.executeQuery(sql);
			stmt.close();

			String view = rs.getString("userid");
			// String view = "https://www.google.com";
			response.sendRedirect(view);
		} catch(Exception e) {
			  e.printStackTrace();
		}
		finally {			
			
		}

なんか上手くいきませんね。executeQuery以降が駄目っぽいです。

servletからmysqlにinsert

servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		// response.getWriter().append("Served at: ").append(request.getContextPath());
		
		// import java.sql.*;
//		Connection db_con = null;
//		PreparedStatement db_st = null;
//		ResultSet db_data = null;
		
		Connection conn = null;
		ResultSet rs = null;
		
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			conn = DriverManager.getConnection("jdbc:mysql://localhost/sampledb","root","");

			Statement stmt = conn.createStatement();
			String sql = "insert into userinfo(userid, status) values ('hoge', 1)";
			int num = stmt.executeUpdate(sql);
			stmt.close();
		} catch(Exception e) {
			  e.printStackTrace();
		}
		finally {
			
		}
		
		
		
	}

mysql> select * from userinfo;
+———+——–+
| userid | status |
+———+——–+
| aaaa123 | 0 |
| asdf123 | 1 |
| hoge | 1 |
| xyzx123 | 2 |
+———+——–+
4 rows in set (0.01 sec)

なるほど♪

make:auth 認証時のエラー処理

resources/lang/en/passwords.phpを変更する。

‘failed’ => ‘These credentials do not match our records.’,
‘throttle’ => ‘Too many login attempts. Please try again in :seconds seconds.’,

目算間違えた。。結構やらなきゃいけない量が大量にあるな。

make:auth後のルーティング

[vagrant@localhost demo]$ php artisan route:list
+——–+———-+————————+——————+————————————————————————+————–+
| Domain | Method | URI | Name | Action | Middleware |
+——–+———-+————————+——————+————————————————————————+————–+
| | GET|HEAD | / | | Closure | web |
| | GET|HEAD | api/user | | Closure | api,auth:api |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController@index | web,auth |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest |
| | POST | password/reset | password.update | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest |
+——–+———-+————————+——————+————————————————————————+————–+

/home はログイン後の画面

routes/web.php

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

resources/views/authに以下のphpファイルが出来ている
– login.blade.php
– register.blade.php
– verify.blade.php
– passwords/email.blade.php
– passwords/reset.blade.php

また、views/layouts/app.blade.php もできている。

app/Http/controllers/Auth にcontrollerもできている。
ForgotPasswordController.php
LoginController.php
RegisterController.php
ResetPasswordController.php
VertificationController.php

database/migration
users_table.php, password_resets_table.php

LoginController、RegisterController、ResetPasswordControllerのリダイレクト先を変更する。デフォルトはhome

protected $redirectTo = '/';

laravelでログイン機能を作ろう

composerをインストールした後に、laravelを入れます。
そうですね、project nameはdemoあたりにしておきましょう。

$ php composer.phar create-project –prefer-dist laravel/laravel demo
Installing laravel/laravel (v5.7.0)

続いてDBをつくる
mysql> create database demo;

DBを設定していく
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=hoge
DB_USERNAME=hoge
DB_PASSWORD=hoge

[vagrant@localhost demo]$ php artisan make:auth
Authentication scaffolding generated successfully.

あれ? なんじゃこりゃ?
[vagrant@localhost demo]$ php artisan migrate
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table

[vagrant@localhost demo]$ php artisan serve –host=192.168.35.10 –port=8000
Laravel development server started:

mysql> use demo
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+—————-+
| Tables_in_demo |
+—————-+
| migrations |
| users |
+—————-+
2 rows in set (0.00 sec)

mysql> describe users;
+——————-+——————+——+—–+———+—————-+
| Field | Type | Null | Key | Default | Extra |
+——————-+——————+——+—–+———+—————-+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | NULL | |
| email | varchar(255) | NO | | NULL | |
| email_verified_at | timestamp | YES | | NULL | |
| password | varchar(255) | NO | | NULL | |
| remember_token | varchar(100) | YES | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+——————-+——————+——+—–+———+—————-+
8 rows in set (0.11 sec)

なんじゃこりゃーーーーーーーーーーーーーーーーーーーーーー??
えええ?
意味が分からん。。
認証機能ね。

/config/auth.php

password_reset tableがないな。。

php artisan serve –host 192.168.35.10 –port 8000

Too many arguments, expected arguments “command”.

ん?

[vagrant@localhost laravel]$ php artisan serve -host=192.168.35.10 -port=8000
Description:
Serve the application on the PHP development server

Usage:
serve [options]

Options:
–host[=HOST] The host address to serve the application on [default: “127.0.0.1”]
–port[=PORT] The port to serve the application on [default: 8000]
-h, –help Display this help message
-q, –quiet Do not output any message
-V, –version Display this application version
–ansi Force ANSI output
–no-ansi Disable ANSI output
-n, –no-interaction Do not ask any interactive question
–env[=ENV] The environment the command should run under
-v|vv|vvv, –verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

hostは –hostですな。

修正しました。
[vagrant@localhost laravel]$ php artisan serve –host=192.168.35.10 –port=8000

さて、まずやっていくのは
1. ログイン機能
2. テーブル作成

このあたりか。
ログインはいきなり実装するのは怖い。

rsync

rsync は、UNIXシステムにおいて、差分符号化を使ってデータ転送量を最小化し、遠隔地間のファイルやディレクトリの同期を行う