'project(website)' 카테고리의 다른 글

First project -final  (0) 2019.09.10
First - admin page 1  (0) 2019.08.23
First - paging  (0) 2019.08.22
First - login session function  (0) 2019.08.21
First - board(front controller, command)  (0) 2019.08.20

'project(website)' 카테고리의 다른 글

second-shopping mall site(login, register, menu)  (0) 2019.09.23
First - admin page 1  (0) 2019.08.23
First - paging  (0) 2019.08.22
First - login session function  (0) 2019.08.21
First - board(front controller, command)  (0) 2019.08.20

AndroidManifest.xml

//uses-permission internet.

//cleartextTraffic true 설정

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.datatransfer">
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".RegisterActivity"></activity>
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

 

activity_login.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoginActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="225dp"
android:orientation="vertical"
android:background="@color/colorPrimary">

<ImageView
android:layout_width="125dp"
android:layout_height="125dp"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:src="@drawable/ic_launcher_foreground"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="hohohoho"
android:textColor="#ffffff"
android:textSize="25dp"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="register help"
android:textColor="#ffffff"
android:textSize="18dp"
android:textStyle="bold"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<EditText
android:layout_width="280dp"
android:layout_height="wrap_content"
android:hint="ID"
android:layout_gravity="center"
android:padding="10dp"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:id="@+id/userId"
android:drawableStart="@drawable/ic_person_black_24dp"
android:drawableLeft="@drawable/ic_person_black_24dp"
android:layout_marginTop="50dp"
android:background="@color/colorPrimary"/>
<EditText
android:inputType="textPassword"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:hint="password"
android:layout_gravity="center"
android:padding="10dp"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:id="@+id/userPwd"
android:drawableStart="@drawable/ic_https_black_24dp"
android:drawableLeft="@drawable/ic_https_black_24dp"
android:layout_marginTop="10dp"
android:background="@color/colorPrimary"/>
<Button
android:layout_width="280dp"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:background="@color/colorPrimaryDark"
android:text="login"
android:id="@+id/loginBtn"
android:layout_marginTop="10dp"
android:layout_gravity="center"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18dp"
android:layout_marginTop="10dp"
android:text="register"
android:id="@+id/registerBtn"/>
</LinearLayout>
</LinearLayout>

</RelativeLayout>

 

activity_register.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RegisterActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/colorPrimary">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="register"
android:textColor="#ffffff"
android:textSize="30dp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:background="@color/colorPrimary"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<EditText
android:layout_width="280dp"
android:layout_height="wrap_content"
android:hint="ID"
android:layout_gravity="center"
android:padding="10dp"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:id="@+id/userId"
android:drawableStart="@drawable/ic_person_black_24dp"
android:drawableLeft="@drawable/ic_person_black_24dp"
android:layout_marginTop="50dp"
android:background="@color/colorPrimary"/>

<EditText
android:inputType="textPassword"
android:layout_width="280dp"
android:layout_height="wrap_content"
android:hint="password"
android:layout_gravity="center"
android:padding="10dp"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:id="@+id/userPwd"
android:drawableStart="@drawable/ic_https_black_24dp"
android:drawableLeft="@drawable/ic_https_black_24dp"
android:layout_marginTop="10dp"
android:background="@color/colorPrimary"/>
<EditText
android:layout_width="280dp"
android:layout_height="wrap_content"
android:hint="email"
android:layout_gravity="center"
android:padding="10dp"
android:textColor="#ffffff"
android:textColorHint="#ffffff"
android:id="@+id/userEmail"
android:drawableStart="@drawable/ic_email_black_24dp"
android:drawableLeft="@drawable/ic_email_black_24dp"
android:layout_marginTop="10dp"
android:background="@color/colorPrimary"/>
<Button
android:layout_width="280dp"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="#ffffff"
android:background="@color/colorPrimaryDark"
android:text="register"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:id="@+id/registerBtn"/>
</LinearLayout>
</LinearLayout>

</RelativeLayout>

 

LoginActivity.java

//URL url = new URL("http://www.uccstudent.com/zLogin.jsp");

package com.example.datatransfer;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class LoginActivity extends AppCompatActivity {
EditText userId, userPwd;
Button loginBtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

userId = (EditText) findViewById(R.id.userId);
userPwd = (EditText) findViewById(R.id.userPwd);
loginBtn = (Button) findViewById(R.id.loginBtn);
loginBtn.setOnClickListener(btnListener);

//register page로 이동
TextView registerButton = (TextView) findViewById(R.id.registerBtn);
registerButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
Intent registerIntent = new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(registerIntent);
}
});
}

class CustomTask extends AsyncTask<String, Void, String>{
String sendMsg, receiveMsg;
@Override
protected String doInBackground(String... strings){
try{
String str;
URL url = new URL("http://10.241.131.162:8080/design/zLogin.jsp");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestMethod("POST");
OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());
sendMsg = "userId="+strings[0]+"&userPwd="+strings[1];
osw.write(sendMsg);
osw.flush();
if(conn.getResponseCode() == conn.HTTP_OK){
InputStreamReader tmp = new InputStreamReader(conn.getInputStream(), "UTF-8");
BufferedReader reader = new BufferedReader(tmp);
StringBuffer buffer = new StringBuffer();
while ((str = reader.readLine()) != null) {
buffer.append(str);
}
receiveMsg = buffer.toString();
} else {
Log.i("result", conn.getResponseCode()+"error");
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return receiveMsg;
}
}

View.OnClickListener btnListener = new View.OnClickListener(){
@Override
public void onClick(View view){
switch(view.getId()){
case R.id.loginBtn:
String loginId = userId.getText().toString();
String loginPwd = userPwd.getText().toString();
try{
String result = new CustomTask().execute(loginId, loginPwd).get();
if(result.equals("true")){
Toast.makeText(LoginActivity.this,"login", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(LoginActivity.this, RegisterActivity.class);
startActivity(intent);
finish();
}else if(result.equals("false")){
Toast.makeText(LoginActivity.this,"wrong ID or Password",Toast.LENGTH_SHORT).show();
userId.setText("");
userPwd.setText("");
}else if(result.equals("noId")){
Toast.makeText(LoginActivity.this,"it doesn't exist",Toast.LENGTH_SHORT).show();
userId.setText("");
userPwd.setText("");
}
}catch(Exception e){
e.printStackTrace();
}break;
}
}
};
}

 

RegisterActivity.java

//URL url = new URL("http://www.uccstudent.com/zRegister.jsp");

package com.example.datatransfer;

import androidx.appcompat.app.AppCompatActivity;

import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class RegisterActivity extends AppCompatActivity {

EditText userId, userPwd, userEmail;
Button registerBtn;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);

userId = (EditText) findViewById(R.id.userId);
userPwd = (EditText) findViewById(R.id.userPwd);
userEmail = (EditText) findViewById(R.id.userEmail);
registerBtn = (Button) findViewById(R.id.registerBtn);
registerBtn.setOnClickListener(btnListener);
}

//연결과 data전송을 위해
class CustomTask extends AsyncTask<String, Void, String>{
String sendMsg, receiveMsg;
@Override
protected String doInBackground(String... strings){
try{
String str;
URL url = new URL("http://10.241.131.162:8080/design/zRegister.jsp");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestMethod("POST");
OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());
sendMsg = "userId="+strings[0]+"&userPwd="+strings[1]+"&userEmail="+strings[2];
osw.write(sendMsg);
osw.flush();
if(conn.getResponseCode() == conn.HTTP_OK){
InputStreamReader tmp = new InputStreamReader(conn.getInputStream(), "UTF-8");
BufferedReader reader = new BufferedReader(tmp);
StringBuffer buffer = new StringBuffer();
while ((str = reader.readLine()) != null) {
buffer.append(str);
}
receiveMsg = buffer.toString();
} else {
Log.i("result", conn.getResponseCode()+"error");
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return receiveMsg;
}
}

//버튼 클릭시
View.OnClickListener btnListener = new View.OnClickListener(){
@Override
public void onClick(View view){
switch(view.getId()){
case R.id.registerBtn:
String joinId = userId.getText().toString();
String joinPwd = userPwd.getText().toString();
String joinEmail = userEmail.getText().toString();
try{
String result = new CustomTask().execute(joinId, joinPwd, joinEmail).get();
if(result.equals("userId")){
Toast.makeText(RegisterActivity.this,"it already exists", Toast.LENGTH_SHORT).show();
userId.setText("");
userPwd.setText("");
userEmail.setText("");
}else if(result.equals("ok")){
userId.setText("");
userPwd.setText("");
userEmail.setText("");
Toast.makeText(RegisterActivity.this,"registered successfully", Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
e.printStackTrace();
}break;
}
}
};
}

 

zRegister.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import = "android.*"%>
<%
String userId = request.getParameter("userId");
String userPwd = request.getParameter("userPwd");
String userEmail = request.getParameter("userEmail");

zDAO zdao = zDAO.getInstance();
String returns = zdao.insertUser(userId, userPwd, userEmail);
out.print(returns);
%>

 

zLogin.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import = "android.*"%>
<%
String userId = request.getParameter("userId");
String userPwd = request.getParameter("userPwd");

zDAO zdao = zDAO.getInstance();
String returns = zdao.loginUser(userId, userPwd);
out.print(returns);
%>

 

zDAO.java

package android;

import java.sql.*;

public class zDAO {

private static zDAO instance = new zDAO();

public static zDAO getInstance() {
return instance;
}

public zDAO() {
}

public String insertUser(String userId, String userPwd, String userEmail) {
Connection conn = null;
PreparedStatement pstmt2 = null;
PreparedStatement pstmt1 = null;
ResultSet rs = null;
String returns = "";
String sql2 = "insert into test VALUES(?,?,?)";
String sql1 = "select userId from test where userId=?";
String url = "jdbc:mysql://localhost:3306/jusung1025";
String uId = "***********";
String uPw = "***********";

try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url,uId,uPw);
pstmt1 = conn.prepareStatement(sql1);
pstmt1.setString(1, userId);
rs = pstmt1.executeQuery();
if(rs.next()) {
if(rs.getString("userId").equals(userId)){
returns = "userId";
}
}else {
pstmt2 = conn.prepareStatement(sql2);
pstmt2.setString(1, userId);
pstmt2.setString(2, userPwd);
pstmt2.setString(3, userEmail);
pstmt2.executeUpdate();

returns = "ok";
}
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
if(pstmt2 != null) pstmt2.close();
if(pstmt1 != null) pstmt1.close();
if(conn != null) conn.close();
}catch(Exception e) {
e.printStackTrace();
}
    }
return returns;
}

public String loginUser(String userId, String userPwd) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
String returns = "";
String sql = "select userId,userPwd from test where userId=?";
String url = "jdbc:mysql://localhost:3306/jusung1025";
String uId = "*******";
String uPw = "********";
try {
Class.forName("com.mysql.jdbc.Driver");
conn = DriverManager.getConnection(url,uId,uPw);
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, userId);
rs = pstmt.executeQuery();
if(rs.next()) {
if(rs.getString("userId").equals(userId) && rs.getString("userPwd").equals(userPwd)) {
returns = "true";
}else {
returns = "false";
}
}else {
returns = "noId";
}
}catch(Exception e) {
e.printStackTrace();
}finally {
try {
if(rs != null) rs.close();
if(pstmt != null) pstmt.close();
if(conn != null) conn.close();
}catch(Exception e) {
e.printStackTrace();
}
}
return returns;
}
}

'android studio' 카테고리의 다른 글

android register db connection using JSP  (0) 2019.09.06
android internet check  (0) 2019.09.05
activity life cycle  (0) 2019.08.14
intent  (0) 2019.08.14
startActivityForResult()(화면전환)  (0) 2019.08.13

0.AndroidManifest.xml

//internet permission

//CleartextTraffic true설정

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.httpproject">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>

 

1.activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="ID"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

<EditText
android:id="@+id/register_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8" />

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="PW"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

<EditText
android:id="@+id/register_pw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="8" />

</TableRow>

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center_horizontal">

<Button
android:id="@+id/register_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="10"
android:text="회원가입" />
</TableRow>
</TableLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

 

MainActivity.java

//url ip값으로 주기

package com.example.httpproject;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;


public class MainActivity extends AppCompatActivity {

Button registerBtn;
EditText idet, pwet;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

setTitle("ORACLE");

registerBtn = (Button)findViewById(R.id.register_btn);
idet = (EditText)findViewById(R.id.register_id);
pwet = (EditText)findViewById(R.id.register_pw);

registerBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
try {
String result;
String id = idet.getText().toString();
String pwd = pwet.getText().toString();

RegisterActivity task = new RegisterActivity();
result = task.execute(id, pwd).get();
} catch (Exception e) {
Log.i("DBtest", ".....ERROR.....!");
}
}
});

}
}

 

RegisterActivity.java

package com.example.httpproject;

import android.os.AsyncTask;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

public class RegisterActivity extends AsyncTask<String, Void, String> {
String sendMsg, receiveMsg;

@Override
protected String doInBackground(String... strings) {
try {
String str;

// 접속할 서버 주소 (이클립스에서 android.jsp 실행시 웹브라우저 주소)
URL url = new URL("http://10.241.131.162:8080/android/data.jsp");

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestMethod("POST");
OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());

// 전송할 데이터. GET 방식으로 작성
sendMsg = "id=" + strings[0] + "&pwd=" + strings[1];

osw.write(sendMsg);
osw.flush();

//jsp와 통신 성공 시 수행
if (conn.getResponseCode() == conn.HTTP_OK) {
InputStreamReader tmp = new InputStreamReader(conn.getInputStream(), "UTF-8");
BufferedReader reader = new BufferedReader(tmp);
StringBuffer buffer = new StringBuffer();

// jsp에서 보낸 값을 받는 부분
while ((str = reader.readLine()) != null) {
buffer.append(str);
}
receiveMsg = buffer.toString();
} else {
// 통신 실패
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

//jsp로부터 받은 리턴 값
return receiveMsg;
}

}

'android studio' 카테고리의 다른 글

android - jsp - database connection  (0) 2019.09.08
android internet check  (0) 2019.09.05
activity life cycle  (0) 2019.08.14
intent  (0) 2019.08.14
startActivityForResult()(화면전환)  (0) 2019.08.13

1. manifiest파일에 다음 내용 추가

MainActivity.java

3.HttpThread.java

'android studio' 카테고리의 다른 글

android - jsp - database connection  (0) 2019.09.08
android register db connection using JSP  (0) 2019.09.06
activity life cycle  (0) 2019.08.14
intent  (0) 2019.08.14
startActivityForResult()(화면전환)  (0) 2019.08.13

'project(website)' 카테고리의 다른 글

second-shopping mall site(login, register, menu)  (0) 2019.09.23
First project -final  (0) 2019.09.10
First - paging  (0) 2019.08.22
First - login session function  (0) 2019.08.21
First - board(front controller, command)  (0) 2019.08.20

Paging.java

//Paging class를 생성하고 변수 선언하고 getter and setter method 를 생성

//startNum와 endNum 는 database query문에 사용될변수로 값을 지정한다

//setTotalCount method 실행시 자동으로 paging method를 실행시킨다

//page: 현재 페이지로 defalut값을 1로설정한다

//처음과 끝 page를 받아올 변수로 beginPage, endPage를 선언한다

//한번에 표시할 record 갯수를 나타낼 변수로 displayRow=10을 선언한다

//한번에 표시할 page의 갯수를 나타낼 변수로 displayPage=10을 선언한다

//prev와 next를 true, false값으로 나타내기위해 boolean형으로 변수를 선언한다

//endPage는 마지막 page를 나타내므로 현재페이지가 10이하일경우 마지막page는 항상 10이여야한다

 

//endPge = Math.ceil(page/displyaPage)*displayPage를 하게되면 page가 10이하일경우

//page/display에서 항상 1 이하의 값이 나오게되고 Math.ceil로 올림을하면 1의값이출력되고

//거기에 display 10을 곱해주면 항상 10의 값이 나오게된다

 

//beginPage는 값이 10일경우 항상 1이나와야하므로 beginPage=endPage-(display-1)로 처리한다

 

//totalPage는 게시글이 하나라도 존재하면 page가 존재해야하므로 Math.ceil(totalCount/displayRow)를 이용한다

 

//next값은 totalPage가 endPage와 같거나 작을경우 false로 안보이게하고 endPage를 초과할경우에 true값을준다

 

//prev값은 beginPage가 1이아닐경우 무조건 표시이므로 beginPage가 1일경우 false로주고 나머지를 true값을설정한다

frontController

//기존에 쓰던데로 boardList.do가 실행될시 bListCommand가 실행되게하고

//bListCommand에 code를 추가시켜서 작동하게한다

bListCommand

// 변수 count를 선언하고 getAllcount method를 이용해 전체 게시글을 int형으로 받아온다

// 현재 page를 1로 선언하고 if문을 통해 page값을 받아온다

// Paging 객체 paging을 선언하고 paging에 page값과 count값을 setting한다

//dao.list method를 호출할때 매개변수를 paging으로 줘서

//Paging에 설정한 getStartNum와 getEndNum를 이용해

//list method에서 startNum와 endNum값을 가져올수 있게한다

//data를 가져와 dtos에 저장한다

//list와 paging에 입력된값을 setting 시킨다 

boardDAO

//list method에서 paging값을 매개변수로 받아와 startNum와 EndNum를 구하고 database 검색에 활용한다

//"select * from"
+"(select * from(select rownum as row_num, bId, bName, bTitle, bContent, bDate, bHit, bGroup, bStep, bIndent from"
+ " (select * from board order by bGroup desc, bStep asc))" 
+"where row_num >= ?) where row_num <=?";

//쿼리문작성시 order by보다 rownum가 먼저수행되므로 rownum을 제외한 값을 먼저 orderby로 정렬시켜준후 rownum을실행해야한다

//dto.setBId(rs.getBId("bId")); dtos.add(dto); 와같이 입력해줄수도있다

paging.jsp

//값을 가져와서 출력한다

//c:url은 boardList.do라는 경로를 action이라는 면수명으로 setting한다

// if test 는 prev가 true일경우 표시하겠다는뜻

//prev값을 누를경우 beginPage-1을하고 action에 setting된 boardList.do를 실행한다는의미

//beginPage와 endPage를 param을 이용해 가져오고 index에 step=1을설정해 

//beginPage부터 endPage까지 1씩 증가시키면서 출력시키겠다는 뜻이다

//param을 이용해 가져온 page값이 index와 같을경우 클릭할수없고 다를경우만 클릭할수있다

//현재페이지는 클릭불가능하게하기위해서이다

//next값이  true일경우 표시하고 클릭할경우 endPage에 1을 증가시키고 action에 setting된 boardList.do를 실행

boardList.jsp

//paging.jsp에 출력된값을 include를 이용해 가져온다

//bListCommand에서 request.setAttribute("paging",paging);을 설정하고

//boardList.jsp에서 value에 paging.page, name에 page값을설정해서

//paging.jsp에서 ${param.page}를 이용해 값을 받아올수있게된다

'project(website)' 카테고리의 다른 글

First project -final  (0) 2019.09.10
First - admin page 1  (0) 2019.08.23
First - login session function  (0) 2019.08.21
First - board(front controller, command)  (0) 2019.08.20
First - navigation, include  (0) 2019.08.17

designTalk.jsp

//session을 변수에저장하고 dao객체생성해 sentMessage method 를 실행하고

//그 결과값을 ldtos arrylist에 저장한다

sendOk.jsp

// id 값과 content값을 변수에 저장하고 dao객체를 생성후 sendMessage method를 실행

 

loginDTO 생성

//Content, Lanswer를 매개변수로 받는 생성자를 생성한다

loginDAO생성

//getConnection 을이용해 db연결하는 method생성

//sendMessage생성 primary key지정과 정렬을 위해 no값을 추가

//sentMessage생성 DTO에서 만든 생성자를 이용해 data를 저장한후

//배열 ldtos에 입력한다

website.jsp

//submit로 data를 전송

websiteOk.jsp

//전송된값을 변수에 저장후 dao객체를 생성해 websiteSave method를 실행

purchase.jsp

//session을 통해 id값을 변수에 저장후 dao객체생성하고 purchaseSaved method를 실행

//pdtos에 저장된값을 출력

purchaseDTO 생성

//가져올값을 매개변수로 생성자를 overloading한다

purchaseDAO

//getConnection method를 이용해 db접속

//websiteSave를 통해 전송된값을 db에 저장

//purchaseSaved를 통해 매개변수로 가져온 id값과 같은 data를 출력해 pdtos에 저장 

result

'project(website)' 카테고리의 다른 글

First - admin page 1  (0) 2019.08.23
First - paging  (0) 2019.08.22
First - board(front controller, command)  (0) 2019.08.20
First - navigation, include  (0) 2019.08.17
First - register, login, modify, logout process  (0) 2019.08.17

+ Recent posts