전체 글
-
[C#] HttpWebRequest Class 활용한 Post 전송2014.02.13
-
[C#] Win7 x64 IIS에서 32bit 응용 프로그램 사용2014.02.13
-
jQuery multi redio button valid check2014.02.13
-
[C#] 중첩 리피터(Nested Repeater) 부모값 호출 하기2014.02.13
-
[ajax] JSONP CROSS SITE 응답 받기2014.02.12
-
spring social2014.02.12
[C#] HttpWebRequest Class 활용한 Post 전송
C#에서 http 프로토콜을 이용한 인터페이스.
protected void HttpCall()
{
String callUrl = "http://localhost:8080/test/call";
String[] data = new String[1];
data[0] = "nikemodel"; // id
data[1] = "password"; // pw
String postData = String.Format("id=&pw=", data[0], data[1]);
HttpWebRequest httpWebRequest = (HttpWebRequest) WebRequest.Create(callUrl);
//인코딩 UTF-8
byte[] sendData = UTF8Encoding.UTF8.GetBytes(postData);
httpWebRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
httpWebRequest.Method = "POST";
httpWebRequest.ContentLength = sendData.Length;
Stream requestStream = httpWebRequest.GetRequestStream();
requestStream.Write(sendData, 0, sendData.Length);
requestStream.Close();
HttpWebResponse httpWebResponse = (HttpWebResponse) httpWebRequest.GetResponse();
StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
String response = streamReader.ReadToEnd();
streamReader.Close();
httpWebResponse.Close();
console.Write("response : " + response);
}'Programming > C#' 카테고리의 다른 글
| [C#] short url 생성(bit.ly) (0) | 2014.02.13 |
|---|---|
| [C#] Win7 x64 IIS에서 32bit 응용 프로그램 사용 (0) | 2014.02.13 |
| [C#] 중첩 리피터(Nested Repeater) 부모값 호출 하기 (0) | 2014.02.13 |
| [C#] Generic 이란. (0) | 2014.01.07 |
[C#] Win7 x64 IIS에서 32bit 응용 프로그램 사용
Win7 x64 IIS 환경 설정
ASP.NET 개발환경을 win7 x64 os로 설치하고 비주얼스튜디오에서 프로젝트를 셋팅하던 도중에 간혹 목격되는 오류 메세지이다.
'/' 응용 프로그램에 서버 오류가 있습니다.
--------------------------------------------------------------------------------
80040154 오류로 인해 CLSID가 {94773112-72E8-11D0-A42E-00A024DED613}인 구성 요소의 COM 클래스 팩터리를 검색하지 못했습니다.
설명: 현재 웹 요청을 실행하는 동안 처리되지 않은 예외가 발생했습니다. 스택 추적을 검토하여 발생한 오류 및 코드에서 오류가 발생한 위치에 대한 자세한 정보를 확인하십시오.
예외 정보: System.Runtime.InteropServices.COMException: 80040154 오류로 인해 CLSID가 {94773112-72E8-11D0-A42E-00A024DED613}인 구성 요소의 COM 클래스 팩터리를 검색하지 못했습니다.
IIS관리자에 응용 프로그램 풀을 확인해 보면
32bit 응용 프로그램 사용 기본이 false로 되어있다.
true로 변경해 주고 IIS 리스타트를 하면 정상적으로 작동한다.
'Programming > C#' 카테고리의 다른 글
| [C#] short url 생성(bit.ly) (0) | 2014.02.13 |
|---|---|
| [C#] HttpWebRequest Class 활용한 Post 전송 (0) | 2014.02.13 |
| [C#] 중첩 리피터(Nested Repeater) 부모값 호출 하기 (0) | 2014.02.13 |
| [C#] Generic 이란. (0) | 2014.01.07 |
jQuery multi redio button valid check
개발을 하다보면 multi radio button에 대한 유효성 검증 로직을 사용할 경우가 있다.
<script>
$J(function() {
document.location.href = '#show';
$J('input:radio').addClass("vm");
var chkVal;
//등록
$J("#btnReg").click(function() {
var chkLen = 0;
var chkLen2 = 0;
$J("[id='tableExample']").each(function(i) {
chkVal = "N";
chkLen2 = 0;
$J(this).find("#trExample").each(function(j) {
chkVal = "N";
$J(this).find("input:radio").each(function() {
if ($J(this).is(":checked") == true) {
chkVal = "V";
}
});
if (chkVal != "V") {
alert((i + 1) + "번 문항의 " + (j + 1) + "번째 직원의 답변을 선택해주세요");
$J(this).find("input:radio")[0].focus();
return false;
} else if (chkVal == "V") {
chkLen2++;
}
});
if ($J(this).find("#trExample").length == chkLen2) {
chkLen++;
} else {
return false;
}
});
});
});
</script>
html 영역 <asp:Repeater ID="rptQuestionList" runat="server" OnItemDataBound="rptQuestionList_OnItemDataBound">
<table id="tableExample">
<asp:Repeater ID="rptAnswerList" runat="server" OnItemDataBound="rptAnswerList_OnItemDataBound">
<tr id="trExample">
<input type="radio" class="vm" id="rdoExample1">
<input type="radio" class="vm" id="rdoExample2">
<input type="radio" class="vm" id="rdoExample3">
</tr>
</asp:Repeater>
</table>
</asp:Repeater>
'Programming > Frontend' 카테고리의 다른 글
| [jQuery] loadingbar plugin (0) | 2014.09.19 |
|---|---|
| jquery ajax method 정리 (0) | 2014.03.12 |
| [ajax] JSONP CROSS SITE 응답 받기 (0) | 2014.02.12 |
| jQuery에서 부모창 제어/접근(opener, parent) (0) | 2014.02.11 |
| jquery hover 효과 (0) | 2013.12.20 |
[C#] 중첩 리피터(Nested Repeater) 부모값 호출 하기
C# Repeater
ASP.NET WebForm에서 중첩 리피터 사용 시 부모에 바인딩된 값을 자식 리피터에서 사용하는 방법
<asp:repeater id="rptQuestionList" runat="server" onitemdatabound="rptQuestionList_OnItemDataBound">
<asp:repeater id="rptAnswerList" runat="server" onitemdatabound="rptAnswerList_OnItemDataBound">
<!-- 방식 1 다이렉트로 접근 //-->
<%# DataBinder.Eval(Container.Parent.Parent, "DataItem.QuestionNo")%>
<!-- 방식 2 aspx.cs 영역에 메소드를 작성하는 방식 //-->
<%#GetQustionNo(Container) %>
</asp:repeater>
</asp:repeater>
Test.aspx.cs
#region 부모리피터 데이타 바인딩
// 중첩리티터에서 부모 리피터 item 호출
protected string GetQustionNo(object itm)
{
RepeaterItem ritm = itm as RepeaterItem;
RepeaterItem parentItm = ritm.Parent.Parent as RepeaterItem;
DataRowView rview = parentItm.DataItem as DataRowView;
return rview["QuestionNo"].ToString();
}
#endregion
'Programming > C#' 카테고리의 다른 글
| [C#] short url 생성(bit.ly) (0) | 2014.02.13 |
|---|---|
| [C#] HttpWebRequest Class 활용한 Post 전송 (0) | 2014.02.13 |
| [C#] Win7 x64 IIS에서 32bit 응용 프로그램 사용 (0) | 2014.02.13 |
| [C#] Generic 이란. (0) | 2014.01.07 |
[ajax] JSONP CROSS SITE 응답 받기
front-end에서 외부 도메인과 통신할 경우 javascript에서 JSONP를 이용하여 ajax통신이 가능하다.
아래 간단한 예제를 활용해 보자.
javascript
$.ajax({
type : "GET",
dataType: "jsonp",
data: {id: "tttt"},
url: "http://www.test2.com/request",
success: function(data) {
$("#result").html(JSON.stringify(data));
},
error: function() {
alert("error");
}
});
java request
@RequestMapping(value = "/request", method = RequestMethod.GET)
public String request(@RequestParam String id, @RequestPrarm String callback) {
Map<string, string> paramMap = new HashMap<string, string>();
paramMap.put("id", id);
paramMap.put("result", "success");
String result = null;
ObjectMapper mapper = new ObjectMapper();
try {
result = mapper.writeValueAsString(paramMap);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(result);
return callback + "(" + result + ")";
}'Programming > Frontend' 카테고리의 다른 글
| jquery ajax method 정리 (0) | 2014.03.12 |
|---|---|
| jQuery multi redio button valid check (0) | 2014.02.13 |
| jQuery에서 부모창 제어/접근(opener, parent) (0) | 2014.02.11 |
| jquery hover 효과 (0) | 2013.12.20 |
| jQuery.noConflict() alias 사용 (0) | 2013.03.24 |
spring social
spring social facebook
-로그인/개인프로필/친구정보 불러오기 테스트.
스프링 소셜 라이브러리를 사용하기 위해 먼저 maven 프로젝트를 생성.
그 전에 facebook 개발자센터에서 appId, secretKey를 발급 받고, 테스트할 URL을 등록이 필요하다.
-propertyorg.springframework.social spring-social-core 1.0.2.RELEASE org.springframework.social spring-social-web 1.0.2.RELEASE org.springframework.social spring-social-facebook 1.0.2.RELEASE org.springframework.social spring-social-facebook-web 1.0.2.RELEASE
@Controller
@RequestMapping("/facebook")
@PropertySource("classpath:/setting.properties")
public class SocialController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
@Resource
private Environment environment;
/**
* index
* 메인
* @param model
* @param param
* @return
*/
@RequestMapping(value = "/index", method = RequestMethod.POST)
public String index(HttpSession session, Model model){
//facebook info setting
Facebook facebook = new FacebookTemplate((String)session.getAttribute("ACCESS_TOKEN"));
FacebookProfile profile = facebook.userOperations().getUserProfile();
//List friends = facebook.friendOperations().getFriendIds();
//byte[] profiles = facebook.userOperations().getUserProfileImage();
String myId = profile.getId();
String myName = profile.getName();
String myEmail = profile.getEmail();
String myGender = profile.getGender();
Map profileInfo = new HashMap();
profileInfo.put("myId", myId);
profileInfo.put("myName", myName);
profileInfo.put("myEmail", myEmail);
profileInfo.put("myGender", myGender);
logger.info("myId=>{}", myId);
model.addAttribute("profileInfo", profileInfo);
return "index";
}
/**
* freiend Info search
* @param session
* @param model
* @return
*/
@RequestMapping(value="/getFriendInfo")
public String getFriendsInfo(HttpSession session, Model model){
Facebook facebook = new FacebookTemplate((String)session.getAttribute("ACCESS_TOKEN"));
List friends = facebook.friendOperations().getFriendIds();
model.addAttribute("friendsList", friends);
return "index";
}
/**
* facebookSignin
* 페이스북 로그인 팝업 호출
* @param response
* @param request
* @param model
* @return
* @scope user_about_me:사용자 본인 정보, publish_stream: 기본적인 쓰기권한, read_friendlists: 친구 목록
* @throws Exception
*/
@RequestMapping(value="/facebookSignIn" , method = RequestMethod.GET)
public String facebookSignin(HttpServletResponse response, HttpServletRequest request, Model model) throws Exception {
logger.info("{}","facebookSignIn START");
String callbackUrl = environment.getProperty("callback.host")+"/social/facebook/facebookAccessToken";
String oauthUrl = "https://www.facebook.com/dialog/oauth?" +
"client_id="+ environment.getProperty("facebook.appId")+"&redirect_uri="+URLEncoder.encode(callbackUrl, "UTF-8")+
"&scope=user_about_me,publish_stream,read_friendlists,offline_access";
model.addAttribute("oauthUrl", oauthUrl);
return "home";
}
/**
* facebookAccessToken
* 페이스북 로그인 결과 리턴
* @param request
* @param model
* @param message
* @param response
* @return
* @throws Exception
*/
@SuppressWarnings("deprecation")
@RequestMapping(value="/facebookAccessToken")
public String getFacebookClientAccessToken(HttpServletRequest request, Model model, @RequestParam(value="message", defaultValue="" , required=false) String message, HttpServletResponse response) throws Exception {
String code = request.getParameter("code");
String errorReason = request.getParameter("error_reason");
String errorDescription = request.getParameter("error_description");
if(logger.isInfoEnabled()){
logger.info("code => " +code);
logger.info("errorReason code => " + errorReason);
logger.info("errorDescription => " + errorDescription);
}
//facebook accessToken call
requestAccesToken(request, code);
return "callback";
}
/**
* facebook accessToken request
* 토큰값 받아옴
* @param request
* @param code
* @throws Exception
*/
public void requestAccesToken(HttpServletRequest request, String code) throws Exception{
String accessToken = "";
String result = "";
String callbackUrl = environment.getProperty("callback.host")+"/social/facebook/facebookAccessToken";
String url = "https://graph.facebook.com/oauth/access_token"+
"?client_id="+environment.getProperty("facebook.appId")+
"&client_secret="+environment.getProperty("facebook.secretKey")+
"&redirect_uri="+URLEncoder.encode(callbackUrl, "UTF-8")+
"&code="+code;
//httpGet 통신
HttpGet httpGet = new HttpGet(url);
DefaultHttpClient httpClient = new DefaultHttpClient();
result = httpClient.execute(httpGet, new BasicResponseHandler());
accessToken = result.split("&")[0].replaceFirst("access_token=", "");
//토큰값 세션처리
setAccessToken(request, accessToken);
}
/**
* setAccessToken
* 토큰값 세션 저장
* @param request
* @param accessToken
* @throws Exception
*/
public void setAccessToken(HttpServletRequest request, String accessToken) throws Exception {
request.getSession().setAttribute("ACCESS_TOKEN", accessToken);
logger.info("ACCESS_TOKEN => " + request.getSession().getAttribute("ACCESS_TOKEN"));
}
}
-home.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
facebook 로그인 하기 Sample
Spring Social Facebook oAuth
|
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
facebook 로그인 하기 Sample
-index.jsp
본인정보 |
| <이미지 태그="https://graph.facebook.com/${pInfo.myId}/picture"> |
|
myEmail: ${pInfo.myEmail} myGender: ${pInfo.myGender} myName: ${pInfo.myName} myId: ${pInfo.myId} |
친구정보 불러오기 |
| <앵커 태그="${pageContext.request.contextPath}/facebook/getFriendInfo">조회 |
|
|
'Programming > Spring' 카테고리의 다른 글
| spring mvc @ResponseBody, @RequestBody json + ajax (2) | 2014.03.12 |
|---|---|
| [Spring] Spring AOP를 이용한 메서드 추적 (0) | 2014.02.13 |
| spring mvc 모델 생성 (0) | 2014.02.11 |
| [Spring] Environment와 @PropertySource (0) | 2014.02.05 |
| 뷰 이름 명시적 지정 :ModelAndView와 String 리턴 타입 (1) | 2014.02.04 |

