Harigami
ログイン
Harigamiは、ログイン不要のコード共有サービスです。コードの投稿後に発行されるURLでコードを共有できます。
PythonやRubyなど一部の言語は、投稿後にオンラインで実行することもできます。
誰でも無料で使えて、広告もありません。コードレビューやスニペットの代わりに使ってみてください。


詳細設定
+
anonymous タイトルなし
Python
# -*- coding: utf-8 -*-
"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
import math

def phi3(x):
    return x[0]*x[1]*math.pi
def XI(x):
    return (math.sin(x[1])*(math.sin(phi3(x)))**2+math.sin(x[0])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[0])/4
def YI(x):
    return (-math.sin(x[1])*math.cos(x[0])*(math.sin(phi3(x)))**2-math.cos(x[0])*math.sin(x[0])*(math.cos(phi3(x)))**2+((math.sin(x[0]))**2)*math.cos(x[1])*math.sin(phi3(x)))/4
def ZI(x):
    return math.cos(x[0])*math.cos(phi3(x))/4
def IX(x):
    return (math.sin(x[0])*(math.sin(phi3(x)))**2+math.sin(x[1])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[1])/4
def XX(x):
    return (((math.sin(x[1]))**2)*(math.sin(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x))*(math.sin(x[0])+math.sin(x[1])))/4
def YX(x):
    return (-math.sin(x[0])*math.cos(x[0])*(math.sin(x[1]))**2+math.sin(phi3(x))*math.cos(x[1])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[0])*math.cos(x[0])))/4
def ZX(x):
    return (-math.sin(x[0])*math.cos(x[1])*math.sin(phi3(x))+math.cos(x[0])*(math.sin(x[1]))**2+math.sin(x[1])*math.cos(x[1])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def IY(x):
    return (-math.sin(x[0])*math.cos(x[1])*(math.sin(phi3(x)))**2-math.sin(x[1])*math.cos(x[1])*(math.cos(phi3(x)))**2+((math.sin(x[1]))**2)*math.cos(x[0])*math.sin(phi3(x)))/4
def XY(x):
    return (-math.sin(x[1])*math.cos(x[1])*(math.sin(x[0]))**2+math.sin(phi3(x))*math.cos(x[0])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[1])*math.cos(x[1])))/4
def YY(x):
    return (math.sin(x[0])*math.cos(x[0])*math.sin(x[1])*math.cos(x[1])-math.sin(phi3(x))*(math.sin(x[0])*(math.cos(x[1]))**2+math.sin(x[1])*(math.cos(x[0]))**2))/4
def ZY(x):
    return (-math.sin(x[0])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[1])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[1])/4
def IZ(x):
    return math.cos(x[1])*math.cos(phi3(x))/4
def XZ(x):
    return (-math.sin(x[1])*math.cos(x[0])*math.sin(phi3(x))+math.cos(x[1])*(math.sin(x[0]))**2+math.sin(x[0])*math.cos(x[0])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def YZ(x):
    return (-math.sin(x[1])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[0])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[0])/4
def ZZ(x):
    return math.cos(x[1])*math.cos(x[0])/4

# import some data to play with
iris = datasets.make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, factor=0.8)

x = iris[0]
W = iris[1]
Y = W+W-1


def my_kernel(A, B):
    b = np.zeros((Y.shape[0], Y.shape[0]))
    for i in range(0,Y.shape[0]):
        for j in range(0,Y.shape[0]):
            x=A[i]
            y=B[j]
            PX=np.array([1/4,XI(x),YI(x),ZI(x),IX(x),XX(x),YX(x),ZX(x),IY(x),XY(x),YY(x),ZY(x),IZ(x),XZ(x),YZ(x),ZZ(x)])
            PY=np.array([1/4,XI(y),YI(y),ZI(y),IX(y),XX(y),YX(y),ZX(y),IY(y),XY(y),YY(y),ZY(y),IZ(y),XZ(y),YZ(y),ZZ(y)])
            b[i][j] += np.dot(PX,PY)
    return b

h = .02  # step size in the mesh

# we create an instance of SVM and fit out data.
clf = svm.SVC(kernel=my_kernel)
clf.fit(x, Y)

# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, x_max]x[y_min, y_max].
x_min, x_max = x[:, 0].min() - 1, x[:, 0].max() + 1
y_min, y_max = x[:, 1].min() - 1, x[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Paired)

# Plot also the training points
plt.scatter(x[:, 0], x[:, 1], c=Y, cmap=plt.cm.Paired, edgecolors='k')
plt.title('3-Class classification using Support Vector Machine with custom'
          ' kernel')
plt.axis('tight')
plt.show()
  • 0
  • 0
anonymous タイトルなし
Python

"""
Spyder Editor

This is a temporary script file.
"""

import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm, datasets
import math

def phi3(x):
    return x[0]*x[1]*math.pi
def XI(x):
    return (math.sin(x[1])*(math.sin(phi3(x)))**2+math.sin(x[0])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[0])/4
def YI(x):
    return (-math.sin(x[1])*math.cos(x[0])*(math.sin(phi3(x)))**2-math.cos(x[0])*math.sin(x[0])*(math.cos(phi3(x)))**2+((math.sin(x[0]))**2)*math.cos(x[1])*math.sin(phi3(x)))/4
def ZI(x):
    return math.cos(x[0])*math.cos(phi3(x))/4
def IX(x):
    return (math.sin(x[0])*(math.sin(phi3(x)))**2+math.sin(x[1])*(math.cos(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x)))*math.sin(x[1])/4
def XX(x):
    return (((math.sin(x[1]))**2)*(math.sin(phi3(x)))**2+math.cos(x[0])*math.cos(x[1])*math.sin(phi3(x))*(math.sin(x[0])+math.sin(x[1])))/4
def YX(x):
    return (-math.sin(x[0])*math.cos(x[0])*(math.sin(x[1]))**2+math.sin(phi3(x))*math.cos(x[1])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[0])*math.cos(x[0])))/4
def ZX(x):
    return (-math.sin(x[0])*math.cos(x[1])*math.sin(phi3(x))+math.cos(x[0])*(math.sin(x[1]))**2+math.sin(x[1])*math.cos(x[1])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def IY(x):
    return (-math.sin(x[0])*math.cos(x[1])*(math.sin(phi3(x)))**2-math.sin(x[1])*math.cos(x[1])*(math.cos(phi3(x)))**2+((math.sin(x[1]))**2)*math.cos(x[0])*math.sin(phi3(x)))/4
def XY(x):
    return (-math.sin(x[1])*math.cos(x[1])*(math.sin(x[0]))**2+math.sin(phi3(x))*math.cos(x[0])*(math.sin(x[0])*math.sin(x[1])-math.cos(x[1])*math.cos(x[1])))/4
def YY(x):
    return (math.sin(x[0])*math.cos(x[0])*math.sin(x[1])*math.cos(x[1])-math.sin(phi3(x))*(math.sin(x[0])*(math.cos(x[1]))**2+math.sin(x[1])*(math.cos(x[0]))**2))/4
def ZY(x):
    return (-math.sin(x[0])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[1])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[1])/4
def IZ(x):
    return math.cos(x[1])*math.cos(phi3(x))/4
def XZ(x):
    return (-math.sin(x[1])*math.cos(x[0])*math.sin(phi3(x))+math.cos(x[1])*(math.sin(x[0]))**2+math.sin(x[0])*math.cos(x[0])*math.sin(phi3(x)))*math.cos(phi3(x))/4
def YZ(x):
    return (-math.sin(x[1])*math.sin(phi3(x))*math.cos(phi3(x))-math.cos(x[1])*math.cos(x[0])*math.cos(phi3(x))+math.sin(x[0])*math.cos(phi3(x))*math.sin(phi3(x)))*math.sin(x[0])/4
def ZZ(x):
    return math.cos(x[1])*math.cos(x[0])/4

# import some data to play with
iris = datasets.make_circles(n_samples=100, shuffle=True, noise=None, random_state=None, factor=0.8)

x = iris[0]
W = iris[1]
Y = W+W-1


def my_kernel(x, Y):
    PX=np.array([1/4,XI(x),YI(x),ZI(x),IX(x),XX(x),YX(x),ZX(x),IY(x),XY(x),YY(x),ZY(x),IZ(x),XZ(x),YZ(x),ZZ(x)])
    PY=np.array([1/4,XI(Y),YI(Y),ZI(Y),IX(Y),XX(Y),YX(Y),ZX(Y),IY(Y),XY(Y),YY(Y),ZY(Y),IZ(Y),XZ(Y),YZ(Y),ZZ(Y)])
    return np.dot(PX,PY)

h = .02  # step size in the mesh

# we create an instance of SVM and fit out data.
clf = svm.SVC(kernel=my_kernel)
clf.fit(x, Y)

# Plot the decision boundary. For that, we will assign a color to each
# point in the mesh [x_min, x_max]x[y_min, y_max].
x_min, x_max = x[:, 0].min() - 1, x[:, 0].max() + 1
y_min, y_max = x[:, 1].min() - 1, x[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])

# Put the result into a color plot
Z = Z.reshape(xx.shape)
plt.pcolormesh(xx, yy, Z, cmap=plt.cm.Paired)

# Plot also the training points
plt.scatter(x[:, 0], x[:, 1], c=Y, cmap=plt.cm.Paired, edgecolors='k')
plt.title('3-Class classification using Support Vector Machine with custom'
          ' kernel')
plt.axis('tight')
plt.show()
  • 0
  • 0
anonymous タイトルなし
PHP

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>編集画面</title>
</head>
	
<body>
	<form method="post" action="kadai_2_06.php">
		<div>
			<label for="pass">パスワード</label>
			<input type="password" name="pass" value="">
		</div>
		<div>
			<label for="editNo">編集番号</label>
			<input type="text" name="editNo" value="">
		</div>
		<input type="submit" name="btn_edit" value="編集">
	</form>
</body>
</html>
  • 0
  • 0
anonymous タイトルなし
PHP
<?php

// メッセージを保存するファイルのパス設定
define( 'FILENAME', './kadai_2_06.txt');

// タイムゾーン設定
date_default_timezone_set('Asia/Tokyo');

// 変数の初期化
$now_date = null;
$data = null;
$file_handle = null;
$split_data = null;
$message = array();
$message_array = array();
$success_message = null;
$error_message = array();
$delete = null;
$del_con = null;
$del_data = array();

//----------------テキストファイルにデータを書き込む-----------------

if(file_exists(FILENAME)){
	$num = count(file(FILENAME)) + 1; 
}else{
	$num = 1;
}

if( isset($_POST['btn_submit']) ) {

	//-----未入力のバリデーション---------
	if(empty($_POST['view_name'])){
		echo '名前を入力してください!';
		exit();
	}
	
	if(empty($_POST['message'])){
		echo 'メッセージを入力してください!';
		exit();
	}
	
	if(empty($_POST['pass'])){
		echo 'パスワードを入力してください!';
		exit();
	}
	
	//------------------------------------
	
	if( $file_handle = fopen( FILENAME, "a") ) {	
		// タイムスタンプ
		$now_date = date("Y-m-d H:i:s");
	
		// 書き込むデータを作成
		$data = $num."<>".$_POST['view_name']."<>".$_POST['message']."<>".$now_date."<>".$_POST['pass']."<>"."\n";
	
		// 書き込み
		fwrite( $file_handle, $data); 
	
		// ファイルを閉じる
		fclose( $file_handle);
		
		//投稿が成功したことを示すメッセージ
		$success_message = 'メッセージを送信しました';
	}	
}

//----------------------------【編集】----------------------------------

//------①送信されてきた編集番号と一致する配列の値を取得------
if(isset($_POST['btn_edit'])){

	if((empty($_POST['editNo']))||(empty($_POST['pass']))){
		echo '編集番号とパスワードの両方を入力してください';
		exit();
	}
	
	$editNo = $_POST['editNo'];
	$edit_con = file(FILENAME);
	for( $j=0; $j<count($edit_con); $j++ ){
		$edit_data = explode("<>", $edit_con[$j]);
			if(($edit_data[4]==$_POST['pass'])&&($edit_data[0]==$editNo)){
				$edit_no = $edit_data[0];
				$edit_name = $edit_data[1];
				$edit_message = $edit_data[2];
				$edit_pass = $edit_data[4];
			}else if(($edit_data[0]==$editNo)&&($_POST['pass']!=$edit_data[4])){
				echo 'パスワードまたは編集番号が違います';
				exit();
			}	
	}
}

//-----------------②メッセージを編集する---------------------
if(isset($_POST['execute_edit'])){
	
	//新しいメッセージをテキストに書き込む
	$editNo = $_POST['keep_editNo'];
	$edit_con = file(FILENAME);
	$now_date = date("Y-m-d H:i:s");
	for( $k=0; $k<count($edit_con); $k++ ){
		$edit_data = explode("<>", $edit_con[$k]);
		if($edit_data[0] == $editNo){
			$edit_data[1] = $_POST['view_name'];
			$edit_data[2] = $_POST['message'];
			$edit_data[3] = $now_date;
			$edit_data[4] = $_POST['pass'];
			$edit_con[$k] = implode("<>",$edit_data)."\n";
			file_put_contents(FILENAME,$edit_con);
		}
	}				
}
//----------------【削除】指定した番号のメッセージを削除--------------------
if(isset($_POST['btn_delete'])){

	if((empty($_POST['deleteNo']))||(empty($_POST['pass']))){
		echo '削除番号とパスワードの両方を入力してください';
		exit();
	}

	$deleteNo = $_POST['deleteNo'];
	$del_con = file(FILENAME);
	
	for( $i=0; $i<count($del_con); $i++ ){
		$del_data = explode("<>", $del_con[$i]);
		if(($del_data[4]==$_POST['pass'])&&($del_data[0]==$deleteNo)){
			array_splice($del_con,$i,1); 
			for( $l=0; $l<count($del_con); $l++ ){
				$down = explode("<>",$del_con[$l]);
				if( $l>=$i ){
					$down[0] = $down[0] - 1;
					$del_con[$l]=implode("<>",$down); 
				}
			}
			file_put_contents(FILENAME,$del_con);
		}else if(($del_data[0]==$deleteNo)&&($del_data[4]!=$_POST['pass'])){
			echo 'パスワードまたは削除番号が違います';
			exit();
		}
	}
}

//-------テキストファイルのデータを掲示板のフォーム下に表示--------

if( $file_handle = fopen( FILENAME,'r') ) {
    
     while( $data = fgets($file_handle) ){	//fgets関数でファイルからデータを一行ずつ全て取得
		
		//preg_split関数で文字列を特定の文字で分割する:
		$split_data = explode("<>",$data);

        $message = array(
        	'post_no' => $split_data[0],
            'view_name' => $split_data[1],
            'message' => $split_data[2],
            'post_date' => $split_data[3]
        );
        array_unshift( $message_array, $message);
    }

    // ファイルを閉じる
    fclose( $file_handle);
}

?>

<!------------------------------<HTML>----------------------------------->

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>簡易掲示板</title>
</head>

<body>
<h2>簡易掲示板(^-^*)</h2>
	<?php if(!empty($success_message)):?>
		<p class="success_message"><?php echo $success_message;?></p>
	<?php endif; ?>
	
	<?php if(!empty($error_message)):?>
		<ul class="error_message">
			<?php foreach($error_message as $value):?>
				<li>・<?php echo $value; ?></li>
			<?php endforeach; ?>
		</ul>
	<?php endif; ?>
	
	<form method="post">
		<div>
			<label for="pass">パスワード</label>
			<input type="password" name="pass" value="<?php if(isset($_POST['btn_edit'])){ echo $edit_pass; } ?>">
		</div>
		<div>
			<label for="view_name">名前</label>
			<input type="text" name="view_name" value="<?php if(isset($_POST['btn_edit'])){ echo $edit_name; } ?>">
		</div>
		<div>
			<label for="message">メッセージ</label>
			<textarea name="message"><?php if(isset($_POST['btn_edit'])){ echo $edit_message; } ?></textarea>
			<input type="submit" name="btn_submit" value="投稿">
			<input type="hidden" name="keep_editNo" value="<?php if(isset($_POST['btn_edit'])){ echo $edit_no; } ?>">
			<input type="submit" name="execute_edit" value="編集">
		</div>
	</form>
	
	<form method="post" action="kadai_2_06_edit.html">
		<div>
			<input type="submit" name="btn_edit" value="投稿を編集">
		</div>	
	</form>
	
	<form method="post" action="kadai_2_06_delete.html">
		<div>
			<input type="submit" name="btn_delete" value="投稿を削除">
		</div>	
	</form>
		
<hr>
<!-------------------フォーム下に表示----------------------->
<section>
	<?php if( !empty($message_array) ): ?>
	<?php foreach( $message_array as $value ): ?>
	<article>
	    <div class="info">
	        <h2><?php echo $value['post_no'].":".$value['view_name']; ?></h2>
	        <time><?php echo date('Y年m月d日 H:i', strtotime($value['post_date'])); ?></time>
	    </div>
	    <p><?php echo $value['message']; ?></p>
	</article>
	<?php endforeach; ?>
	<?php endif; ?>
</section>
	
</body>
</html>

  • 0
  • 0
anonymous タイトルなし
PHP
<?php
echo "こんな感じで共有できるみたいです。";
  • 0
  • 0
anonymous タイトルなし
JavaScript
class SetTime{
	constructor(){
		this.currentTime = 0;
		this.newDiv = document.createElement("div");
		this.insertedEle = document.getElementsByClassName("ytp-left-controls")[0];
		this.targetEle = document.getElementsByClassName("ytp-time-current")[0];
		this.insertDiv = document.createElement("div");
		this.newDiv.style.cssText = "font-size: 109%;display: inline-block;vertical-align: top;padding: 0 5px;white-space: nowrap;line-height: 35px;"
		this.newContent = document.createTextNode("none"); 
    	this.newDiv.appendChild(this.newContent);
    	this.insertedEle.insertAdjacentElement("beforeend",this.newDiv);
	}
	converter(){
		var result;
		var hour,minute,second;
		var organizedTime = this.currentTime.match( /((?<hour>\d+):)?(?<minute>\d+):(?<second>\d+)/ );
		hour = Number(organizedTime.groups.hour);
		minute = Number(organizedTime.groups.minute);
		second = Number(organizedTime.groups.second);
		result = (hour?hour*3600:0)+(minute?minute*60:0)+(second?second:0);
		return result;
	}
	getUrl(){
		let url;
		const headTags = document.body.children;
		for(let tag of headTags){
			const attribute = tag.getAttribute('name');
			if(attribute == "twitter:url"){
				url = tag.getAttribute("content");
				console.log(url);
			}
		}
		return url;
	}
}

window.onload = function() {
	var setTime = new SetTime();
	setTime.targetEle.addEventListener('click', function(ele) {
	    setTime.currentTime = ele["path"][0].textContent;
	    convertedTime = setTime.converter();
	    const url =setTime.getUrl();
	    setTime.newContent.textContent = url + "&t=" + convertedTime;
	    document.getSelection().selectAllChildren(setTime.newDiv);
	    document.execCommand("copy");
	}, false);
}
  • 0
  • 0
anonymous タイトルなし
Python
dw = 300
dh = 50
L = 4

Wx = torch.rand(dh, dw, requires_grad=True)# 勾配計算できるように
Wh = torch.rand(dh, dh, requires_grad=True)# 勾配計算できるように
Wy = torch.rand(L, dh, requires_grad=True)# 勾配計算できるように
bh = torch.rand(dh,1, requires_grad=True)# 勾配計算できるように
by = torch.rand(L,1, requires_grad=True)# 勾配計算できるように
embed_model = torch.nn.Embedding(N_VOCAB, 300)

for ID_list in ID_list2[:3]:
    ht = torch.tensor([0.0]*dh) # h0
    ht = ht.view(50,1)
    print('h0_shape', ht.shape)
    for ID in ID_list:
        x = embed_model(torch.tensor(ID))
        x = x.view(300,1)
        ht = torch.nn.functional.tanh(torch.matmul(Wx, x) + torch.matmul(Wh, ht) + bh)
    y = torch.nn.functional.softmax(torch.matmul(Wy,ht)+by, dim=0)
    print('y:', y)
  • 0
  • 0
anonymous タイトルなし
Python
# RNN実装開始
dw = 300
dh = 50
L = 4

Wx = torch.rand(dh, dw, requires_grad=True)# 勾配計算できるようにしておく
Wh = torch.rand(dh, dh, requires_grad=True)# 勾配計算できるようにしておく
Wy = torch.rand(L, dh, requires_grad=True)# 勾配計算できるようにしておく
bh = torch.rand(dh,1, requires_grad=True)# 勾配計算できるようにしておく
by = torch.rand(L,1, requires_grad=True)# 勾配計算できるようにしておく
embed_model = torch.nn.Embedding(N_VOCAB, 300)

for ID_list in ID_list2[:3]:
    ht = torch.tensor([0.0]*dh) # h0
    ht = ht.view(50,1)
    print('h0_shape', ht.shape)
    for ID in ID_list:
        x = embed_model(torch.tensor(ID))
        x = x.view(300,1)
        ht = torch.nn.functional.tanh(torch.matmul(Wx, x) + torch.matmul(Wh, ht) + bh)
    y = torch.nn.functional.softmax(torch.matmul(Wy,ht)+by, dim=0)
    print('y:', y)
  • 0
  • 0
anonymous タイトルなし
Python
# NN
d = len(x_train[0])
L = 4
model = torch.nn.Sequential()
model.add_module('fc1', torch.nn.Linear(d, L))

optimizer = torch.optim.SGD(model.parameters(), lr=0.1)
criterion = torch.nn.CrossEntropyLoss()

# 学習モード
model.train()

n_epoch = 500
for i in range(n_epoch):
    optimizer.zero_grad()
    
    output = model(x_train)
    loss = criterion(output, y_train)
    loss.backward()
    optimizer.step()
    print(loss)
  • 0
  • 1
anonymous タイトルなし
Java
package com.db.java;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/InputServlet")
public class InputServlet extends HttpServlet {
	protected void doPost(
							HttpServletRequest request,
							HttpServletResponse response
						)
						throws
							ServletException,
							IOException
	{
		request.setCharacterEncoding("UTF-8");

		String name = request.getParameter("name");
		String age = request.getParameter("age");

		ManGenerator gen = new ManGenerator(name, age);
		request.setAttribute("human", gen.getHuman());

		RequestDispatcher rd = request.getRequestDispatcher("output.jsp");
		rd.forward(request, response);

	}
}
  • 0
  • 1