REST¼Ü¹¹ÓëJavaʵÏÖ1——REST¸ÅÄî
ÓÉÓÚÓиöºÏ×÷ÏîÄ¿£¬Óõ½ÁËREST£¬ÎÒÃÇÕâ±ßµÄ·þÎñÆ÷ÊÇjavaµÄ£¬ºÏ×÷·½ÄDZßÖ÷ÒªÊÇPHP»·¾³£¬ÎªÁËÔ¶³Ìµ÷ÓõÄÎÊÌ⣬ʹÓÃÁËREST×÷ΪAPIµÄʵÏÖ·½
°¸¡£ÏÖÔÚÏîÄ¿×öµÃ²î²»¶àÁË£¬ÏÂÃæ¼ÇÏÂ×Ô¼ºµÄÒ»µãÐĵã¬ËãÊDZʼǰɡ£
REST£¨Representational State Transfer£©µÄ˵·¨À´×Ô“Architectural Styles and the Design of Network-based
Software Architectures”
£¨Roy Fielding£¬University of California -
Irvine£¬2000£©£¬ÊÇFielding´óÅ£µÄһƪ²©Ê¿ÂÛÎÄ£¬´ÓÍøÉÏËÑË÷ÏÂÓ¦¸Ã¿ÉÒÔÕÒµ½ÖÐÎÄ°æ¡£Ê×ÏÈREST¸ù±¾²»ÊǸö¼¼Êõ£¬Ö»ÊÇÒ»¸ö¼Ü¹¹·½Ê½µÄ×Ü
³Æ£¬¸úweb
serviceҲû̫´ó¹Øϵ£¬Ö»ÊÇ´ÕÇÉËü¿ÉÒÔÂú×ã×î¼òµ¥µÄÔ¶³ÌÐÅÏ¢»ñÈ¡µÄÐèÒª¡£RESTÒ²ÍêÈ«²»ÊÇж«Î÷£¬ÆäʵÔçÆÚµÄHTML¾²Ì¬ÍøÒ³¶¼ÊÇREST£¬Ö»²»
¹ýËæן÷ÖÖ¶¯Ì¬½Å±¾ÓïÑÔµÄʹÓ㬻¥ÁªÍøµÄ¼Ü¹¹Ò²Æ«ÀëÁËÔçÆÚµÄÉ趨£¬RESTµ¹ÊÇÓе㲦ÂÒ·´ÕýµÄζµÀ¡£
RESTµÄÖ÷ÒªÌØÕ÷°üÀ¨£º
1£¬ËùÓеĶ«Î÷¶¼ÊÇ×ÊÔ´£¬×ÊÔ´ÓÃURI±íʾ£¬Ã¿Ò»¸ö»á»°¶¼ÊÇÎÞ״̬µÄ¡£
Õâ¾ä»°É¶Òâ˼£¬¼ÇµÃÒÔÇ°µÄ¾²Ì¬ÍøÒ³²»£¬http://localhost/hello.jspÕâʵ¼Ê¾ÍÊÇÒ»¸ö×ÊÔ´£¬Õâ¸öURI¾ÍÊÇËûµÄµØÖ·¡£Äã¿Ï
¶¨ËµÕâô¼òµ¥»¹ÓÃѧREST£¿£¬¶Ô£¬REST¾ÍÊÇÕâô¼òµ¥£¬µ«ÊÇÇé¿öÔÙ¸´ÔÓÒ»µã£¬±ÈÈçҪд¸ö¹ºÂòÉÌÆ·µÄÒ³Ã棬ÔÛÃÇÓÃJSF»òÕßstruts£¬´Óºǫ́
SessionÈ¡¸ö¿Í»§ID£¬ÔÙ´Ó¹ºÎï³µÀïÍ·°ÑÉÌÆ·ÁбíÈ¡³öÀ´£¬ÎÒÃǸßÐ˵ÄдÁËÒ»¸öhttp://localhost/buyProduct.doÍê³ÉÁË
Õâ¸ö¹¦ÄÜ£¬ÄÇôÕâ¸öhttp://localhost/buyProduct.doµÄURI¾Í²»ÊÇRESTÁË£¬ËûÒÀÀµÓÚÔËÐÐʱ»·¾³ºÍSessionÀïµÄ±ä
Á¿£¬ÕâÑùµÄURI²»Äܱ»Öظ´Ö´ÐУ¬Ò²¾ÍÊÇ˵ֱ½ÓÕ³µ½ä¯ÀÀÆ÷ÔËÐп϶¨Òª±¨´íµÄ¡£ÊDz»ÊÇRESTÒ²ºÜÈÝÒ׿´£¬ÕâÍæÒâͨ¹ýURIÄÜ·ÃÎʲ»£¬ÄÜ·ÃÎʾÍÊÇREST¡£
2£¬¹«¿ªÄ¿Â¼½á¹¹Ê½µÄ URI
¿´ÁËÉÏÃæÄǸöÀý×Ó£¬ÄÇôÔõôдÕâ¸öURIÄØ£¬ÆäʵRESTÏ£ÍûµÄURIÊDzÉÓÃĿ¼½á¹¹Ê½µÄURI£¬ÓÃÒ»ÖÖ´ø²ã´ÎµÄ½á¹¹±íʾ¶Ô×ÊÔ´µÄ»ñÈ¡£¬±ÈÈçÎÒÒª
»ñÈ¡ÂÛ̳µÄÒ»¸ötopic£¬URIµÄ¶¨Òå¾Í¿ÉÒÔ±íʾ³Éhttp://localhost/discussion/topics/103£¬ÔÚÕâÀï
topics¾ÍÊÇÉÏÎÄÎÒÃÇ˵µ½µÄ×ÊÔ´£¬ºóÃæµÄ103ÊÇ×ÊÔ´µÄID¡£ÕâÑùµÄURI¼ò½àÃÀ¹Û£¬ËÑË÷ÒýÇæÓѺ㬿ÉÒÔ±»ä¯ÀÀÆ÷»º´æ£¬Óë»á»°×´Ì¬Î޹أ¬È»ºóÄã¿ÉÄÜÒª
ÎÊÁË£¬ÄÇÎÒÒÔǰдµÄhttp://localhost/discussion/topics?id=103ÕâÑùµÄURIÄØ£¿ÆäʵÕâÖÖÒ²¿ÉÒÔËã
REST£¬URIµÄ±íʾ·½Ê½ÊÇÓÉ¿ª·¢Õß¾ö¶¨µÄ£¬µ±È»http://localhost/discussion/topics?id=103ÕâÖÖд·¨Ëƺõ¶Ô
ËÑË÷ÒýÇæ²
Ïà¹ØÎĵµ£º
// ¼òÒ×JAVA»ñÈ¡ÍøÒ³ÓÐЧÓÊÏäµØÖ· ---by 77
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class solo7 {
public static void main(String args[]){
  ......
Ò»¸ö¼òµ¥µÄË«»÷¾ÍÄÜÔËÐÐjarÎļþµÄ´ò°ü¹ý³Ì:
http://blog.csdn.net/ihc523/archive/2009/10/11/4636832.aspx
eclipseµ¼³öjarÎļþÔÙ½«Ëüת»»³Éexe¿ÉÖ´ÐÐÎļþ:
http://hi.baidu.com/%C4%CF%BA%BD%CC%EC%CF%C2/blog/item/1601a381ac9af9d1bd3e1e3d.html
´òJar°üµÄÒ»¸öEclipse²å¼þFatJar:
http://blog.csdn.net/lqsmn613/ar ......
eclipseÑ¡Ò»¸ö±äÁ¿ºó£¬Õâ¸öÀàÀïµÄ¸Ã±äÁ¿²»±äÉ«ÎÊÌâ½â¾ö£º
alt + shift + o
/**
* дÈëÈÕÖ¾
* filePath ÈÕÖ¾ÎļþµÄ·¾¶
* code ҪдÈëÈÕÖ¾ÎļþµÄÄÚÈÝ
*/
public
static
boolean
print(String filePath,String code) {
try
{
File tofile
=
new
File(filePath);
......