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://blog.csdn.net/weixin_33912453/article/details/91890915

猜你喜欢

转载自blog.csdn.net/djrm11/article/details/107238462