java 설치 확인

 

cmd창 열고

 

java -version     그러면 자바 설치 가 되어 있다면 설치 버젼이 나옴

 

java

 

javac

 

echo %classpath%

이렇게 나오면 오류나니

 

환경 변수에 새로 만들기

CLASSPATH

.;

 

이렇게 해줌~~

 

 

<IDE :통합 개발 환경 [integrated development environment, 統合開發環境] >

1.에디터

2.JSK 툴

3.webbrowser(client)

4.web server를 편리하게

 


JSP(잘할려면)---->servlet



Servlet - 서버(Serv)에 들어가는 작은(let) 프로그램이다..



HTTP Server   -----servlet(요청과 응답을 다룰수 있는 기능이 있음)


       ↑           

(request ) (response)

                      ↓

Webbrowser   ------http client










package test.web.servlet;

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

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

import org.apache.jasper.tagplugins.jstl.core.Out;


public class TestServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/plain;charset=euc-kr");//http header부분
		
		int num = Integer.valueOf(request.getParameter("num"));//request로 부터 num이라는 파라미터를 받겠다.(숫자여도 문자열로 받기 때문에 Integer)
		
		PrintWriter out = response.getWriter();
		for(int i=1;i<=9;i++){
			out.println(num + " * " + i + " = " +num*i+"</br>");
		}
		
		//server client 연결...stream
		out.println("Hello World");
		out.flush();//buffer안에 있는 데이터를 브라우져로 전송
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}


http://localhost:8080/WebApp/TestServlet  이러면 오류가 남


http://localhost:8080/WebApp/TestServlet?num=7

이렇게 뒤에다  num 값을 주면 7단 구구단이 출력된다.



'JSP > 2012.04강의(MySQL)' 카테고리의 다른 글

복습3 선언부(Declaration),request 기본 객체,리다이렉트(Redirect)  (0) 2012.07.06
복습2 스크립트 요소  (0) 2012.07.05
예비  (0) 2012.05.30
예비  (0) 2012.05.30
예비  (0) 2012.05.30

RegisterUser1 (redirect 연습)

package com.ch5.action;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.opensymphony.xwork2.Action;

public class RegisterUser1 implements Action{

    private String userId;
    
    @Override
    public String execute() throws Exception {
             
        return SUCCESS;
    }
    
    public String getUserId() {
        String id="";
        try {
            id =URLEncoder.encode(userId,"utf-8");
        }catch(UnsupportedEncodingException e){
            e.printStackTrace();
        }
        return id;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }    
}



struts-ch5.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <package name="ch5" namespace="/ch5" extends="struts-default">
         
        
        <!-- redirect -->
        <action name="register" class="com.ch5.action.RegisterUser1">
            <interceptor-ref name="params"/>
            <result name="success" type="redirect">registerSuccess.jsp?userId=${userId}</result>
        </action>
    </package>
</struts>




 registerForm1.jsp (redirect 연습)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>chain 연습</title>
</head>
<body>
<form action="register.action" method="post">
id:<input type="text" name="userId"><br/>
<input type="submit" value="로그인">
</form>
</body>
</html>



                 registerSuccess.jsp (redirect 연습)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>redirect 연습</title>
</head>
<body>
<h1>${param.userId}님 환영합니다.</h1>
</body>
</html>




Chapter04.zip


redirectAction


redirectAction 리절트 타입의 동작 원리는 result 리절트 타입과 동일하다. result 리절트 타입은 리다이렉트할 URL을 지정하였지만, redirectAction 리절트 타입은 actionName 파라미터를 사용하여 리다이렉트 대상이 될 액션 이름을 지정한다.


<action name="UserRegAction" class="action.UserRegAction">
     <interceptor-ref name="params"/>
     <result name ="success" type="redirectAction">
       <param name="actionName">LoginAction</param>
       <param name="userId">${userId}</param>
       <param name="message">${message}</param>
     </result>
  </action>

<action name="LoginAction" class="action.LoginAction">
    <intercepter-ref name="params"/>
    <result name="success">/jsp/userRegSuccess.jsp</result>
 </action>




<global-results/>


액션 요청의 결과를 이한 result 요소는 action 요소의 자식 요소로 설정한다. 경우에 따라서는 여러개의 action 요소에 동일한 result 요소가 설정되는 경우가 있다.


로그인 페이지나 에러페이작 대표적인 예일것이다. 이런 페이지들이 여러 action 요소에 중복되어 설정되는 것을 피하기 위한  방법으로 global-result를 사용할수있다.


<package name="sample" extends="struts-default">
     <global-results>
          <result name="login">/jsp/login.jsp</result>
          <result name="error">/jsp/error.jsp</result>
     </global-results>
     
     <action name="sample" class"tutorial.SampleAction">
          <result name="success">/jsp/smple.jsp</result>
     </action>
</package>



sample 액션을 수행한후 리턴 코드 값으로 success 를 되돌리면 local result에 정의된 success result 에 의해 sample.jsp를 결과 페이지로 출력한다. 만일 sample 액션의 수행후 리턴 코드 값으로 login혹은 error를 되돌릴 경우에는 일차적으로 결과페이지 localresult에서 찾는다 localresult에서 찾지못하면 패키지 내 정의된 <global-results> 에서 찾는다.

+ Recent posts