2012年12月3日月曜日

ものぐさな院生のDWR入門

どうも,立ち位置が微妙な院生の矢ヶ崎です.
3日目は僕が使ってるDWRというものについて書いていきます.

DWRって?

JavaScriptから直接Javaのメソッドを叩けるよく分からない技術です.
研究室で数年前流行ってました(今は多分僕しか使ってません).


なんで使ってるの?

クライアント,サーバ間で通信する為の記述が面倒臭いから使ってます.
AjaxだのPostだのでリクエスト飛ばしてgetAttributeでどーのこーのして
処理が終わったらレスポンスにイソイソ値を入れてとか・・・

いちいち書くのが面倒くせぇ!!ので使ってます.
因みにセキュリティ的にどうのとか書き方的にどうのとか全く気にしてないので知りません.
あとこれしか書けることがn・・・ゲフン
そこ,「またDWRかよ…」とか言わない;


何が良いの?

  • サーブレットを書く必要が無い.
  • だからrequestやらresponseやらに値を出し入れする事もない.
  • Javaさえ書ければ簡単にサーバー側を書ける!(多分).

DWRについてもちっと詳く

JavaScriptからJavaのメソッドが直接叩けます.
例えばControllerクラスのloginCheck(String,String)みたいなメソッドがあれば
JavaScript側でController.loginCheck("admin","areare");で呼び出せます.

準備

1:DWRからdwr.jarを落とす.
2:web.xmlのweb-app以下に下記を追加する.

 Direct Web Remoter Servlet
 DWR Servlet
 dwr-invoker
 uk.ltd.getahead.dwr.DWRServlet
 
  debug
  true
 


 dwr-invoker
 /dwr/*

3:WEB-INF以下にdwr.xmlを作成する.


 
  
 


例:testパッケージ内のCalculatorクラスをcalcという名前で
アプリケーションが終了するまでインスタンスを生存させる場合.



これでおしまい.

scopeについて

DWRで生成されるJavaインスタンスの生存期間が指定できます.
何も書かないとメソッドを叩く度に生成されます.

  • application アプリケーション全体で一つのインスタンスを生成. 
  • session セッション単位. 
  • request リクエスト毎.
  • page ページ毎.
  • script ページを表示している間.

確認の仕方

アプリケーションを実行しアドレスの末尾に「/dwr」とつけてアクセスするとデバッグページが表示されます.(http://localhost:8080/application/dwrみたいな感じ)


使える引数

JavaとJS間では以下のように値を受け渡しできます.
Java ⇔ JavaScript
boolean  論理型
Byte,Short,Integer,Long,Float,Double  数値型
Character,String  文字列型
JavaBeansとJavaオブジェクトも受け渡し可能です.

使い方(JS側)

HTMLに以下を記述する.(Helloクラスの場合)




これでHelloクラスのメソッドを叩くことができます.
例えば下記のようなメソッドがある場合
public String helloName(String name){
 return "Hello "+name;
}
js側でこんな風に呼び出します.(コンソールに「Hello Yaga」って出ます)
Hello.helloName("Yaga",callbackFunc);
function callbackFunc(returnData){
 console.log(returnData);
}
引数が1つ多いと思いますが,DWRでJavaメソッドを呼び出すと
最後の引数+1にメソッドの戻り値が返ってきます.
上記の場合helloNameメソッドの結果をcallbackFunk関数で受け取ってます.
(引数のreturnDataに戻り値が入ってます)

引数にJavaBeansやJavaオブジェクトを使う方法

dwr.xmlのallow以下に以下のように書きます.
JavaBeans以外のJavaオブジェクトを利用する場合は
converterをobjectにします.

後はreturnData.propertyのようにアクセスできます.
var name;
var id;
var age;
School.getStudentData("studentName",function(returnData){
 name = returnData.name;
 id = returnData.id;
 age = returnData.age;
 console.log("学籍番号:"+id+" 氏名:"+name+" 年齢:"+age);
});
var addStudentData = {name:"Meso",id:"C123456",age:10};
School.setStudentData(addStudentData);
10~11行目はBeanDataをサーバー側に送る記述を書いてます.

ちょっと便利なutil関数

JS側に書いてインポートしてるutil.jsを使って色々できます.
ここにはその一部を紹介します.

dwr.util.getValue(id)

引数で指定したid属性を取ってきます,まとめて取ってくるgetValuesってのもあります.

dwr.util.setValue(id,value)

引数で指定したid属性の値を変更します.

dwr.util.addOptions(id,OptionData)

idで指定したセレクトボックスのOptionを追加します.
サーバーからオプションの一覧をStringの配列で返して第2引数に突っ込むだけでOKです.

他にも色々あるので興味のある人は見てみて下さいutil.js


以上になります
特別,必要な技術って訳じゃないですが
やってみると意外と便利だったりするので興味のある人は是非試してみてください.

そんなわけで4日目は前回node.jsについて書いてくれた高木君にバトンタッチします.

それではまた ノシ

73 件のコメント:

  1. Thanks for sharing, nice post! Post really provice useful information!

    Giaonhan247 chuyên dịch vụ mua hộ hàng mỹ với các mặt hàng từ pandora úc hay từ web ebay việt nam cùng với bảng giá gửi hàng đi mỹ uy tín, giá rẻ.

    返信削除
  2. คาสิโนออนไลน์ที่น่าเชื่อถือและมีความเป็นมืออาชีพที่สุดในตอนนี้
    โปรโมชั่นGclub ของทางทีมงานตอนนี้แจกฟรีโบนัส 50%
    เพียงแค่คุณสมัคร สล็อตออนไลน์ กับทางทีมงานของเราเพียงเท่านั้น
    ร่วมมาเป็นส่วนหนึ่งกับเว็บไซต์คาสิโนออนไลน์ของเราได้เลยค่ะ
    สมัครสล็อตออนไลน์ >>> Goldenslot
    สนใจร่วมสนุกกับ คาสิโนออนไลน์ คลิ๊กได้เลย
    มีทั้งคาสิโนออนไลน์ หวยออนไลน์ ฟุตบอลออนไลน์ สล็อตออนไลน์ และอื่นๆอีกมากมาย

    返信削除
  3. If you are looking for the online assignment help service provider then you should definitely go for AllAssignmentHelp.com. We offer all types of subjects assignment helps at the best price.

    返信削除
  4. . Our specialists are mainstays of our administration. These journalists are completely fruitful in their training that they endeavor hard to give splendid work on task composing.
    science homework help
    PR homework help
    math homework help

    返信削除
  5. A discussion board post is an academic task that is often assigned in high schools, colleges, and universities. The essential purpose of such an assignment is to enable the students to demonstrate their writing, research, and analytical skills. do my coursework for me

    返信削除
  6. Great, I must say and thanks for sharing this informative post. I am really impressed that there is so much information about this subject that have been uncovered and you’ve done your best,MyAssignmenthelp.com is giving help to students who are stressed with their homework help and submit their assignment on time. we are already trusted by thousands of students who struggle to write their academic papers and also by those students who simply want online homework writing service to save their time and make life easy.

    返信削除
  7. An introduction to DWR for graduate students thanks sharing great article.It is one of the best information which you are providing. I love your blog.Get best service Web Design Riyadh you visit here site.

    返信削除
  8. Learn more about DWR this example and intro such amazing.This is a great inspiring article. I am pretty much pleased with your good work.The top company Cleaning Company Dubai provide good service of cleaning.

    返信削除
  9. Thanks for coming up with these kinds of whiter than white write ups. If you guys unable to deal with your assignment and seeking assignment help Sydney service then hire assignment writer.

    返信削除
  10. edes Jahr buchen tausende Reisende unsere bewährten sowie umfangreichen Dienstleistungen und das aus gutem Grund. Mit 30 Jahren Erfahrung in den Bereichen Vollcharterflüge, Privatflugzeug Mieten und Serviceleistungen bewegen wir unsere Kunden zuverlässig von einem Reiseziel zum anderen. Besonders freuen dürfen wir uns von FlightTime über die große Anzahl zufriedener Reisegäste, die sich immer wieder für unser Team bestehend aus professionellen Charterexperten entscheiden. Unsere Kunden wählen für sich ganz bewusst die routinierte und exklusive Abwicklung sämtlicher Transferdetails aus. Wir stehen Ihnen überall in der Welt rund um die Uhr – 24 Stunden am Tag und 7 Tage die Woche – mit unserem ganzheitlichen Charterflug-Service zur Verfügung. Für weitere Informationen rufen Sie uns an unter +49-(0)4292-81119-0.

    返信削除
  11. As this blog is in relation to the graduates. I have something for those who are still in the process of graduating. If you are having trouble with your
    Business Assignment do visit us.



    返信削除
  12. Great Article. Thanks for sharing valuable information. Keep Posting. NLP Tools

    返信削除
  13. Are you feeling stressed while composing your accounting homework? Take Accounting Assignment Help to finish your assigned task before the due dates and without having any stress. Time to raise your numbers via experts’ assistance.
    Accounting Homework Help
    Accounting Assignments
    Accounting Assignment
    Do my Accounting Assignment Help
    Do my Accounting Homework Help
    PEEL Paragraph

    返信削除
  14. Great post! The information you shared is great and very helpful for all. I am Tom Walker professional blogger, academic consultants at assignmenthelp provider website ABCassignmenthelp.com

    返信削除
  15. myassignmenthelp strive to meet the need of customized assignment help of students from Universities across Australia. With our team of enthusiastic and unwavering writing experts, our aim is to help every student improve the academic grades and submit optimum quality assignments that are 100% unique meeting the University guidelines. Connect with us now to understand how it works and start the unique experience of customised writing help.

    返信削除
  16. I am trying to open my software, it is showing me QuickBooks won't open message. That’s why, I am worrying more about it.

    返信削除
  17. Your article is so convincing that I never stop myself from appreciating this. Thank you for posting this. If you want to get experts’ advice for your homework writing, hire an academic writer via Online Assignment Help and share your concerns properly. You will get a wonderful chance to save your time and present effective papers for your project submission.
    Online Assignment Help
    Assignment Help Online
    Assignment Helper

    返信削除
  18. Nepal Tour Packages I have a long desire to travel Nepal once in the whole life. Now, I am planning a short Nepal Tour with my family.
    Nepal Tour Package

    返信削除
  19. Such a valuable post. I like it very much and I like your choice words also. Please post some more topics related to online help because I also work in the online professional support industry which provides support of Outlook. I am waiting for your next valuable post.
    How do I contact outlook by phone?
    How do I contact Outlook support?
    Is there a phone number for Outlook support?
    Outlook Support Phone number
    Microsoft Outlook Support
    Outlook Support
    Outlook Support Number

    返信削除
  20. This write up is really good which gives the clear understanding how to scale up your knowledge stream without any difficulty. If you want to add some valuable impact in your data, you can use the feature of Microsoft office 365 download for getting the best result.Visit here:- https://www.office365download.co/
    office 365 download
    Download Office 365
    Microsoft office 365 download
    download Microsoft office 365

    返信削除
  21. The mentioned points in this guide are very informative and helped me to resolve my issue in a very proficient manner. At the time of solving my query I got stuck at one point, so I called at outlook Support Phone number and the technician who answered my call guided me thoroughly to get rid of my issue. I really appreciate the hardworking of that guy, who helped me during my crisis of time and never leave my side until problem didn’t get resolved. Therefore, I personally suggest everyone to get hold of Microsoft outlook Support if you really want to resolve your query related to your Outlook.
    How do I call Outlook support?
    Is there a phone number for Outlook support?
    Windows support
    Microsoft windows support
    Office 365 Support
    Microsoft Office 365 Support
    Microsoft 365 Support
    Office 365
    Microsoft Office 365
    Microsoft Office Support
    Microsoft Office Support number
    Microsoft Office Support Phone number

    返信削除
  22. When I try to open company files, I am experiencing QuickBooks Error 80029c4a. This is the most common error that is making me more irritating. This error code mainly takes place, when I face difficulties to open the company files.

    返信削除
  23. Take Assignment help in Saudi Arabia if you don’t want to craft your papers. If you want to finish your papers without any stress, take experts’ assistance from professional academic writers and accomplish your work without any stress.
    Assignment help Saudi Arabia
    Assignment help

    返信削除
  24. I was going through your website, and got really great matter here. I must say that your content is authentic and knowledgeable. I’m going to be your regular reader now. By the way, I am a booking associate at Hawaiian airlines booking. If any time, you want to book your hawaiian airlines Reservations, contact us.

    返信削除
  25. Avail of Australian Assignment Help if you want to take the help of Australian writers. It may difficult to cope with the tough study structure of Australian university but you get effective writing skills using online assignment writing services at the best price.
    Assignment Help Online
    Online Assignment Help

    返信削除
  26. Browsed several sites for deals and offers on flight tickets but got none. But here I got what I wanted. I’m fully impressed and satisfied with its services. Well, hello there! I’m working at American Airlines Reservations. We offer affordable deals for flight tickets booking. Contact us now to save money on tickets.

    返信削除
  27. Borrow experts' assistance via online assignment help for completing your homework on time. Students can enhance their marks and understand how to explain given questions in the correct format.
    Online assignment help
    assignment help online
    assignment helper
    online assignment helper

    返信削除
  28. Thanks for sharing this post. Accounting help is here. accounting classes online

    返信削除
  29. Simply drop your files in the dropzone. Make sure to drop all VCF file that you want to combine at once. The online service will automatically merge your VFC files and start a download of the single vcf-merge file that contains all uploaded contacts.

    返信削除
  30. Hello, I would like to thank you for sharing this interesting information. What is more, the material provided here will be useful for a lot of people. I was actually looking for someone who will rewrite my essay. Nevertheless, thanks a lot,

    返信削除

  31. 'I'm highly impressed by the piece of thoughts you have shared on this portal. all the best
    connect us on Assignment Help can shed your burden of assignments with a return of qualitative assignments.
    Law Assignment Help
    Programming Assignment Help
    Management Assignment Help
    My Assignment Help

    返信削除
  32. Quicken is the financial assistance that manages all the accounts and financial related chores. Therefore, stopping such software may result in a big problem, such as you won’t be able to see your quicken files or access them. Sometimes low network, server issue or slow internet connection cause this error. Hence, to solve such a situation you should consult a trained technician, who has skills and years of experience. Quicken techniques are very friendly with the software and also with all the errors, and can immediately solve quicken download error 15500.
    Quicken Online Backup
    Quicken Error CC-587
    quicken download error 324
    quicken download error 106
    Quicken Error Code 105
    generate access code capital one 360

    返信削除
  33. Hi, thank you for writing this excellent piece of content. I am really flabbergasted! Your article helped me clear my head around this topic. Also, anyone who is looking for some additional assignment help online can visit my company’s site. They are providing low cost high quality Assignment Help to students. I know writing assignments can be a real pain. So it is better that you take someone’s help. Why should you not contact them instead of wasting or dreading for failing the grade? Don’t do that. You can get better grades with some academic help.
    Assignment Help Online
    Best Assignment Help
    Assignment Helper
    Assignment Help In USA
    Online Assignment Help
    Assignment Help Company
    Assignment Help Experts
    Assignment Help Service
    Online Assignment Help Services

    返信削除
  34. NOBLEQQ MERUPAKAN Situs Poker Online TERBAIK DENGAN WINRATE TERTINGGI SE ASIA WA :+8551090383

    返信削除
  35. Nice Post...
    I am a fresh user of HP printer and operating my printing machine for printing the documents properly. From a few days, my HP printer is not responding properly. When I go for applying a printing command to my HP printer, I am experiencing HP printer not working issue. This issue is very intricate for me. Even I have taken the quick support from hp.com/support, but nothing is helpful for me. Hence till now, I am experiencing this technical glitch. So please anyone can provide the quick solutions to resolve HP printer not working issue.
    support.hp.com
    www.hp.com/support
    www.support.hp.com



    返信削除
  36. Truly, this article is really one of the very best in the history of articles. I am a antique 'Article' collector and I sometimes read some new articles if I find them interesting.
    And I found this one pretty fascinating and it should go into my collection.
    Learn English Grammar in Bangla
    Learn English in Bangla
    Bangla
    English speaking
    English speaking course
    English
    English short stories for kids
    English short stories
    1000 +English short stories for kids
    Edu blogs
    Education Blogs
    english grammar in hindi

    返信削除
  37. Logical Reasoning Test app can be very helpful if you want to prepare or improve your Reasoning Score, IQ score, Critical Thinking Ability.
    This Logical Reasoning app is designed as a preparation tool to help candidates who want to start preparing for various competitive exams and guide the people to solve Aptitude questions or Logical Reasoning Questions for anyone who is preparing for bank exams, railway exams, SSC exams, and various other exams

    返信削除
  38. SSC CGL 2020 English Application can be very helpful to improve your English score. This SSC CGL English Previous Paper has several tests on English section like important words, one word substitutes, synonyms, antonyms, idioms and phrases,sentence improvement, Common errors and spelling tests.
    This SSC CGL 2020 App English Previous Paper App contains important words and test on various English sections which are asked in exams like SSC CGL 2020 , SSC CHSL , SSC CPO, SSC CGL tier 2 SSC CGL Mains etc.

    返信削除
  39. This English Grammar app is the best English learning app offline for android phone. This English grammar offline free is available at free of cost.
    If you are looking for an offline grammar learning, this English Grammer in Hindi app is the right choice for you. This grammar English is mainly designed for students, prospective candidates for competitive exams, English learners at beginning stage.
    English Grammar app offline is the best way to improve your Hindi Grammar. This English Grammar Book Offline helps you to learn the rules of grammar in English language.

    返信削除
  40. sbcglobal email settings: If you are going to use Sbcglobal for your email applications I suggest you should discuss the pros and cons of sbcglobal from the sbcglobal customer service team. They know more than you and they will guide you properly for the sbcglobal.

    返信削除
  41. When you open a QuickBooks Company File, you may encounter QuickBooks Script Errorand due to lack of technical knowledge you won’t fix it. In that case, you simply need to read the blog as here we discuss in details.
    QuickBooks Error 80070057
    QuickBooks Error Code 404
    Capital One QuickBooks Error Code
    QuickBooks Error Code 15106
    QuickBooks Error 1328
    QuickBooks Error 1904

    返信削除
  42. I am a web developer and software engineer currently living in the United States. My interests range from technology to entrepreneurship. I am also interested in web development, programming, and writing.
    office.com/setup
    www.office.com/setup
    office.com/setup
    www.office.com/setup
    office support

    返信削除

  43. AVG Antivirus is designed to secure your device like PC, Mobile and other. AVG requires activation through avg Technology is being advanced day by day, and so we have become dependent on technologies for our works. With these technologies, obviously, it’s dark side has increased as well.
    avg.com/retail |
    www.avg.com/retail |
    install avg with license number |
    www.avg.com/activation |
    avg download

    返信削除
  44. Thanks for sharing this is such a great post. Students can easily get the best finance assignment help services from the professional experts of myassignmentexperts.com. Our team of experts has amazing and great knowledge in finishing all your task accurately and in the asked format. So, students can easily get help in finance assignment writing services today and score high grades.

    返信削除
  45. If searching a student homework help website that provides you the best homework helpers then visit MAHO which is the website that does homework for you. Hiring experts from top websites lead you to achieve top grades in your exams. We can write all the kind of homework paper for you when placed an order with us.

    返信削除
  46. Take Online Assignment Help and finish your academic documents before the deadlines. Avail of the online academic writing services when you don’t want to lose your marks and degrade your academic performance in any condition. Make your project submission worthy of American universities using expert’s assistance.
    Online Assignment
    help with my assignment
    Assignment Help Service

    返信削除
  47. Great article and lovely post. I would like to congratulate you on your post and I want to tell you that I am also here to promote or we can say for digital marketing. I have web pages for different products that you get below and I am here to promote all those given web pages.
    Microsoft tech support number,
    Microsoft support,
    how do I contact Microsoft tech support,
    Microsoft customer service,
    Outlook tech support,
    Outlook support,
    Outlook customer service,
    Outlook customer service number,
    Microsoft Outlook support number,
    How do I contact Microsoft Outlook support?,
    How do I contact outlook customer support?,
    Thank You.

    返信削除
  48. An expert standpoint of the brand picture causes you construct trust among your clients. A very much structured logo gives notion about your association's imaginative powers just as business possibilities. Subsequently, Logo Design services

    返信削除
  49. Are you not able to eradicate unnecessary Facebook problems directly from the experts? Aren’t you able to get the one stop solution to from the reliable source? We are here all the time in order to provide you a better experience in a hassle free and efficient manner. Just give us a call at our Facebook Number.

    返信削除
  50. Are you not able to eradicate unnecessary Facebook problems directly from the experts? Aren’t you able to get the one stop solution to from the reliable source? We are here all the time in order to provide you a better experience in a hassle free and efficient manner. Just give us a call at our Facebook Number.

    返信削除
  51. TouristVisaOnline.com is one of the rapidly growing companies which offers E-visas to different countries in all over the world. We provide United Arab Emirates visa , Kenya visa , Uganda visa , Qatar visa , etc. We offers 24/7 service center support, the fastest turn-around time and 15 years of experience. Just complete the simple application form, upload document, pay visa fee and get your e visa at mail. https://www.touristvisaonline.com/

    返信削除
  52. It was a very good post indeed. I thoroughly enjoyed reading it in my lunch-time. I Will surely come and visit this blog more often.
    Att Email Support
    Att Email Settings
    At&t Email
    Att Email
    Read more: https://www.3citcians.com/att-email-support
    Thanks for sharing your blog.

    返信削除
  53. My Assignment Experts Service is a well-established and prominent name in providing high-quality strategic marketing assignment help to students for almost a decade.
    You can trust our academic ghostwriters completely to get the best quality write-ups including case studies, research proposals, dissertations and theses, and more.
    It is the best strategic marketing planning process assignments help service.
    Students should always keep themselves ready to meet the university requirements to achieve good grades, moreover, they prefer attending lengthy classes instead of writing assignments.
    Students who are not comfortable with writing assignments can avail of strategic marketing assignment help at comparatively low prices.

    返信削除
  54. The increasing users of Whatsapp are becoming responsible for the expanding number of content to share. People are always in search of some kind and quality content which they can share with their loved ones and relatives via Whatsapp.
    Sad Urdu Status

    返信削除
  55. خرید بلیط هواپیما با گسترش روز افزون استفاده از اینترنت دچار تحولات زیادی شده است به طوری که امروزه بلیط هواپیما به مقاصد مختلف را می توان به صورت اینترنتی خریداری کرد. این روش دارای مزایای زیادی است که موجب می شود متقاضیان زیادی از این روش به صورت گسترده و روز افزون استفاده کنند. صرفه جویی در زمان و هزینه، سرعت و جابجایی در سفرهای بین شهری مسافران، باعث شده تا متقاضیان زیادی از روش خرید اینترنتی بلیط هواپیما استفاده نمایند. حق انتخاب گسترده تر مسافران یکی دیگر از مزایای استفاده از اینترنت در به دست آوردن بلیط دلخواه می باشد. با مراجعه به سایت تیک بان می توانید انواع بلیط هواپیما را به مقاصد مختلف و با قیمت های ارزان و اقتصادی مشاهده کرده و بهترین گزینه را رزرو کنید. - خرید بلیط هواپیما تیک بان - خرید بلیط اتوبوس - خرید بلیط قطار - چارتر

    返信削除
  56. Online aviation writing services has become very popular among college aviation coursework writing students seeking Aviation Research Paper Help and aviation essay writing services.

    返信削除
  57. Really very happy to say, your post is very interesting to read. I never stop myself to say something about it. You’re doing a great job.Keep it up
    office.com/setup

    返信削除
  58. Go to office setup website to download and install the full version of Microsoft Office on your device. Follow the direct download link and instructions for guidance on installing Microsoft Office 365 on your computer.

    office.com/setup

    返信削除

  59. Get Instant solution for Norton setup with product key. This is a activation keys for Norton Users. Renew your Norton antivirus with product key from fill and activate norton antivirus in system.

    norton.com/setup

    返信削除
  60. MyAssignmentHelpline is an academic writing service provider in Australia where you get first-rate assignment support at a reasonable price. Dedicated support is one of the most sought after characteristics of our team of assignment helper online experts.

    Australian Assignment Helper | Online Assignment Help Sydney Australia

    返信削除
  61. We have a year of the best experience in tutoring and providing to the student of the MY and most of My homework help UK service students are having professional experience in their respective fields.
    Assignment help
    Online physics homework help
    Do my research paper
    Write my law assignment
    Essay assignment help online

    返信削除