how to add session id using URLConnection


I am trying to upload an image to a server using server url. For this i am using java.net api. After sending request , it is returning a response that shows session invalid. I am getting the session id from that server but unable to add it. How can i add session id using HttpURLConnection while sending request to server. Is their any way to solve this?


Session ID is stored in a cookie, in JavaEE its name is jsessionid, and you add it like that:

httpURLConnection.setRequestProperty(
    "Cookie","JSESSIONID=" + your_session_id);



source - http://stackoverflow.com/questions/14979288/how-to-add-session-id-using-urlconnection







'Development > Java' 카테고리의 다른 글

java - file memory  (0) 2014.10.30
java - json-simple parse  (0) 2014.08.19
java - local host ip address  (0) 2014.02.13
java - HttpURLConnection  (0) 2014.02.07
java - 화폐 원 단위 콤마 표시  (2) 2013.10.02
Posted by linuxism
,

mongodb - $in, $all

DB/MongoDB 2014. 4. 16. 10:44



Performance

Queries that use the $all operator must scan all the documents that match the first element in the $allexpression. As a result, even with an index to support the query, the operation may be long running, particularly when the first element in the $all expression is not very selective.


출처 - http://docs.mongodb.org/manual/reference/operator/query/all/#op._S_all








MongoDB $in, $and, Implicit $and, $all

> db.users.insert({"_id":"01", joined: new Date(), "likes":["tennis", "golf", "basketball"]});
> db.users.insert({"_id":"02", joined: new Date(), "likes":["basketball", "tennis", "golf"]});
> db.users.insert({"_id":"03", joined: new Date(), "likes":["golf", "basketball", "tennis"]});
> db.users.insert({"_id":"04", joined: new Date(), "likes":["tennis", "golf"]});
> db.users.insert({"_id":"05", joined: new Date(), "likes":["golf", "tennis"]});
> db.users.insert({"_id":"06", joined: new Date(), "likes":["golf", "basketball"]});
> db.users.insert({"_id":"07", joined: new Date(), "likes":["basketball", "golf"]});
> db.users.insert({"_id":"08", joined: new Date(), "likes":["tennis", "basketball"]});
> db.users.insert({"_id":"09", joined: new Date(), "likes":["basketball","tennis"]});
> db.users.insert({"_id":"10", joined: new Date(), "likes":[]});
> db.users.insert({"_id":"11", joined: new Date(), "likes":["golf"]});
> db.users.insert({"_id":"12", joined: new Date(), "likes":["tennis"]});
> db.users.insert({"_id":"13", joined: new Date(), "likes":["basketball"]});
> db.users.insert({"_id":"14", joined: new Date(), "likes":"golf"});
> db.users.insert({"_id":"15", joined: new Date(), "likes":"tennis"});

> db.users.count()
15

> db.users.find({$and:[{likes:"tennis"}, {likes:"golf"}]})
{ "_id" : "01", "joined" : ISODate("2013-10-24T05:52:26.733Z"), "likes" : [  "tennis",  "golf",  "basketball" ] }
{ "_id" : "02", "joined" : ISODate("2013-10-24T05:52:26.795Z"), "likes" : [  "basketball",  "tennis",  "golf" ] }
{ "_id" : "03", "joined" : ISODate("2013-10-24T05:52:26.835Z"), "likes" : [  "golf",  "basketball",  "tennis" ] }
{ "_id" : "04", "joined" : ISODate("2013-10-24T05:52:26.878Z"), "likes" : [  "tennis",  "golf" ] }
{ "_id" : "05", "joined" : ISODate("2013-10-24T05:52:26.914Z"), "likes" : [  "golf",  "tennis" ] }

> db.users.find({likes:{$in:["golf", "tennis"]}})
{ "_id" : "01", "joined" : ISODate("2013-10-24T05:52:26.733Z"), "likes" : [  "tennis",  "golf",  "basketball" ] }
{ "_id" : "02", "joined" : ISODate("2013-10-24T05:52:26.795Z"), "likes" : [  "basketball",  "tennis",  "golf" ] }
{ "_id" : "03", "joined" : ISODate("2013-10-24T05:52:26.835Z"), "likes" : [  "golf",  "basketball",  "tennis" ] }
{ "_id" : "04", "joined" : ISODate("2013-10-24T05:52:26.878Z"), "likes" : [  "tennis",  "golf" ] }
{ "_id" : "05", "joined" : ISODate("2013-10-24T05:52:26.914Z"), "likes" : [  "golf",  "tennis" ] }
{ "_id" : "06", "joined" : ISODate("2013-10-24T05:52:26.945Z"), "likes" : [  "golf",  "basketball" ] }
{ "_id" : "07", "joined" : ISODate("2013-10-24T05:52:26.967Z"), "likes" : [  "basketball",  "golf" ] }
{ "_id" : "08", "joined" : ISODate("2013-10-24T05:52:27.001Z"), "likes" : [  "tennis",  "basketball" ] }
{ "_id" : "09", "joined" : ISODate("2013-10-24T05:52:27.030Z"), "likes" : [  "basketball",  "tennis" ] }
{ "_id" : "11", "joined" : ISODate("2013-10-24T05:52:27.083Z"), "likes" : [  "golf" ] }
{ "_id" : "12", "joined" : ISODate("2013-10-24T05:52:27.106Z"), "likes" : [  "tennis" ] }
{ "_id" : "14", "joined" : ISODate("2013-10-24T05:52:27.160Z"), "likes" : "golf" }
{ "_id" : "15", "joined" : ISODate("2013-10-24T05:52:27.185Z"), "likes" : "tennis" }

> db.users.find({likes:{$all:["golf", "tennis"]}})
{ "_id" : "01", "joined" : ISODate("2013-10-24T05:52:26.733Z"), "likes" : [  "tennis",  "golf",  "basketball" ] }
{ "_id" : "02", "joined" : ISODate("2013-10-24T05:52:26.795Z"), "likes" : [  "basketball",  "tennis",  "golf" ] }
{ "_id" : "03", "joined" : ISODate("2013-10-24T05:52:26.835Z"), "likes" : [  "golf",  "basketball",  "tennis" ] }
{ "_id" : "04", "joined" : ISODate("2013-10-24T05:52:26.878Z"), "likes" : [  "tennis",  "golf" ] }
{ "_id" : "05", "joined" : ISODate("2013-10-24T05:52:26.914Z"), "likes" : [  "golf",  "tennis" ] }

> db.users.find({$and:[{likes:"golf"}, {likes:"tennis"}]})
{ "_id" : "01", "joined" : ISODate("2013-10-24T05:52:26.733Z"), "likes" : [  "tennis",  "golf",  "basketball" ] }
{ "_id" : "02", "joined" : ISODate("2013-10-24T05:52:26.795Z"), "likes" : [  "basketball",  "tennis",  "golf" ] }
{ "_id" : "03", "joined" : ISODate("2013-10-24T05:52:26.835Z"), "likes" : [  "golf",  "basketball",  "tennis" ] }
{ "_id" : "04", "joined" : ISODate("2013-10-24T05:52:26.878Z"), "likes" : [  "tennis",  "golf" ] }
{ "_id" : "05", "joined" : ISODate("2013-10-24T05:52:26.914Z"), "likes" : [  "golf",  "tennis" ] }

{$and:[{key1:value1}, {key1:value2}]}가 {key1:value1, key2:value2}가 동일한기는 하지만
단, key1과 key2가 다른 키일 경우에 $and와 동일한다.
key1과 key2가 동일 키일 경우에는 key2:value2의 조건만을 비교하므로 반드시 주의!!!

> db.users.find({likes:"golf", likes:"tennis"})
{ "_id" : "01", "joined" : ISODate("2013-10-24T05:52:26.733Z"), "likes" : [  "tennis",  "golf",  "basketball" ] }
{ "_id" : "02", "joined" : ISODate("2013-10-24T05:52:26.795Z"), "likes" : [  "basketball",  "tennis",  "golf" ] }
{ "_id" : "03", "joined" : ISODate("2013-10-24T05:52:26.835Z"), "likes" : [  "golf",  "basketball",  "tennis" ] }
{ "_id" : "04", "joined" : ISODate("2013-10-24T05:52:26.878Z"), "likes" : [  "tennis",  "golf" ] }
{ "_id" : "05", "joined" : ISODate("2013-10-24T05:52:26.914Z"), "likes" : [  "golf",  "tennis" ] }
{ "_id" : "08", "joined" : ISODate("2013-10-24T05:52:27.001Z"), "likes" : [  "tennis",  "basketball" ] }
{ "_id" : "09", "joined" : ISODate("2013-10-24T05:52:27.030Z"), "likes" : [  "basketball",  "tennis" ] }
{ "_id" : "12", "joined" : ISODate("2013-10-24T05:52:27.106Z"), "likes" : [  "tennis" ] }
{ "_id" : "15", "joined" : ISODate("2013-10-24T05:52:27.185Z"), "likes" : "tennis" }

이것은 결국 아래와  동일한 결과이다.
> db.users.find({likes:{$in:["tennis]}})
> db.users.find({likes:{$all:["tennis]}})
하지만 그럴거면 아래와 같이 쓰는것이 졸겟지....
> db.users.find({likes:"tennis"})



출처 - http://wonie777.blogspot.kr/2013/10/mongodb-in-and-implicit-and-all.html



'DB > MongoDB' 카테고리의 다른 글

mongo - v2.6 error  (0) 2014.04.25
mongodb gridfs - find files_id  (0) 2014.04.22
mongodb - array(list) update  (0) 2014.04.05
mongodb - $all, list/array에서 검색  (0) 2014.03.21
mongodb - $elemMatch, list/array에서 검색  (0) 2014.03.21
Posted by linuxism
,


Html 파일에서 contentType에 따른 File Type...

이걸 이용해서 File download가 가능하다..

 

application/acad 
AutoCAD drawing files
dwg

application/clariscad
ClarisCAD files
ccad

application/dxf
DXF (AutoCAD)
dxf

application/msaccess
Microsoft Access file
mdb

application/msword
Microsoft Word file
doc

application/octet-stream
Uninterpreted binary
bin

application/pdf
PDF (Adobe Acrobat)
pdf

application/postscript
PostScript, encapsulated PostScript,
Adobe Illustrator
ai, ps, eps

application/rtf
Rich Text Format file
rtf rtf

application/vnd.ms-excel
Microsoft Excel file
xls

application/vnd.ms-powerpoint
Microsoft PowerPoint file
ppt

application/x-cdf
Channel Definition Format file
cdf

application/x-csh
C-shell script
csh csh

application/x-dvi
TeX
dvi dvi dvi

application/x-javascript
JavaScript source file
js

application/x-latex
LaTeX source file
latex

application/x-mif
FrameMaker MIF format
mif

application/x-msexcel
Microsoft Excel file
xls

application/x-mspowerpoint
Microsoft PowerPoint file
ppt

application/x-tcl
TCL script
tcl

application/x-tex
TeX source file
tex

application/x-texinfo
Texinfo (emacs)
texinfo, texi 

application/x-troff
troff file
t, tr, roff t, tr, roff

application/x-troff-man
troff with MAN macros
man 

application/x-troff-me
troff with ME macros
me

application/x-troff-ms
troff with MS macros
ms

application/x-wais-source
WAIS source file
src

application/zip
ZIP archive
zip

audio/basic
Basic audio (usually m-law)
au, snd

audio/x-aiff
AIFF audio
aif, aiff, aifc

audio/x-wav
Windows WAVE audio
wav 

image/gif
GIF image
gif

image/ief
Image Exchange Format file
ief

image/jpeg
JPEG image
jpeg, jpg jpe 

image/tiff
TIFF image
tiff, tif

image/x-cmu-raster
CMU Raster image
ras

image/x-portable-anymap
PBM Anymap image format
pnm

image/x-portable-bitmap
PBM Bitmap image format
pbm

image/x-portable-graymap
PBM Graymap image format
pgm

image/x-portable-pixmap
PBM Pixmap image format
ppm

image/x-rgb
RGB image format
rgb

image/x-xbitmap
X Bitmap image
xbm

image/x-xpixmap
X Pixmap image
xpm

image/x-xwindowdump
X Windows Dump (xwd) 
xwd

multipart/x-gzip
GNU ZIP archive
gzip

multipart/x-zip
PKZIP archive
zip

text/css
Cascading style sheet 
css

text/html
HTML file
html, htm

text/plain
Plain text
txt 

text/richtext
MIME Rich Text
rtx

text/tab-separated- values
Text with tab-separated values
tsv

text/xml
XML document
xml

text/x-setext
Struct-Enhanced text 
etx

text/xsl
XSL style sheet
xsl

video/mpeg
MPEG video
mpeg, mpg, mpe 

video/quicktime
QuickTime video
qt, mov

video/x-msvideo
Microsoft Windows video
avi

video/x-sgi-movie
SGI movie player format
movie

 

이런 것들도 있지만,,

JSP에서..

<%

    response.setHeader("Content-Type", "aapplication/x-msdownload");
    response.setHeader("Content-Disposition", "attachment;filename=파일명;");
%>

<%=파일내용출력%>

 

요케 하면 무조건 download가 가능하다..

 

이래도 이해가 안가신다면

 

' Feel Free to Add Your Own Content-Types Here
    Select Case strFileType
        Case ".asf"
            ContentType = "video/x-ms-asf"
        Case ".avi"
            ContentType = "video/avi"
        Case ".doc"
            ContentType = "application/msword"
        Case ".zip"
            ContentType = "application/zip"
        Case ".xls"
            ContentType = "application/vnd.ms-excel"
       ' Case ".ppt"
        '    ContentType = "application/vnd.ms-PowerPoint"
        Case ".gif"
            ContentType = "image/gif"
        Case ".jpg", "jpeg"
            ContentType = "image/jpeg"
        Case ".wav"
            ContentType = "audio/wav"
        Case ".mp3"
            ContentType = "audio/mpeg3"
        Case ".mpg", "mpeg"
            ContentType = "video/mpeg"
        Case ".rtf"
            ContentType = "application/rtf"
        Case ".htm", "html"
            ContentType = "text/html"
        Case ".asp"
            ContentType = "text/asp"
        Case Else
            'Handle All Other Files
            ContentType = "application/octet-stream"
    End Select

 

요걸 참고해서 붙여보시라 그럼 잘 돌아갈것이다.. 누헤헤헤헤



출처 - http://blog.ohmynews.com/icorea77/35629



'Development > HTML' 카테고리의 다른 글

html - role attribute  (0) 2014.05.06
html - <meta> http-equiv Attribute, X-UA-Compatible  (0) 2014.04.29
HTML DOM  (0) 2014.03.06
html - 웹킷(webkit)  (1) 2013.12.10
html - iframe 안에서 밖으로 자바스크립트 통신하기  (0) 2013.07.27
Posted by linuxism
,