Web项目添加Jersey支持

1.加入jersey的jar包,包括api,ex,lib

2.在web.xml中增加配置:

<filter>

         <filter-name> Jersey Web Application</filter-name >

         <filter-class> org.glassfish.jersey.servlet.ServletContainer</filter-class >

         <init-param>

              <param-name> jersey.config.server.provider.packages</param-name >

              <param-value> webservices</param-value >

         </init-param>

  </filter >

  <filter-mapping >

      <filter-name >Jersey Web Application </filter-name>

      <url-pattern >/rest/* </url-pattern>

  </filter-mapping >

3.新建java文件:

@Path( "/updateLocationService")

public class UpdateLocationService {

      @Autowired

      ManageditemManagerAO itemAO;

      @Autowired

      UserManagerAO userAO;

      

      @GET

      @Produces(MediaType.TEXT_PLAIN)

      public String updateLocation( @QueryParam( "equipment_id") String eqId, @QueryParam( "location") String location,

                   @QueryParam( "user") String user, @QueryParam( "password") String password) {

             if ( location == null || location.length() == 0) {

                   return "Error:location is empty";

            }

             if ( eqId == null || eqId.length() == 0) {

                   return "Error:equipment_id is empty";

            }

             if (LdapHelper. verifyAccountAndPwd(user, password) == false) {

                   return "Error:user/password not correct,please use your compute login user&password";

            }

            StorageManagementManageditemExt item = itemAO.getItemByEquipmentId( eqId);

             if( item == null){

                   return "Error:Can't find item by equipment_id:" +eqId ;

            }

             item.setLocation( location);

             itemAO.updateItem( item, userAO.getUserByUserName( user).getId());

             return "Success!";

      }

}

4.在浏览器中输入url:http://localhost:8880/nams/rest/updateLocationService/就会自动调用

转载于:https://my.oschina.net/ffse54s/blog/735133

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值