本帖最后由 ilearn 于 2014-08-19 22:20:14 编辑

解决方案 »

  1.   

    # 3 secondresource.java
    import javax.ws.rs.POST;
    import javax.ws.rs.Path;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    import javax.ws.rs.Consumes;
    import javax.ws.rs.core.MediaType;
    @Path("/queryprivi")
    public interface secondresource {@POST  
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public int querymyprivil(@PathParam("useranme") String usrname,@PathParam("thepass") String thepass,@PathParam("thesecret") String thesecret);}#4 queryaccount.javaimport java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    public class queryaccount implements secondresource{ public int querymyprivil( String usrname, String thepass,String thesecret)
    {
    String drivername="com.mysql.jdbc.Driver";
      String url="jdbc:mysql://localhost:3306/test";
      String username="root";
      String password="password";
      Connection conn=null;
      PreparedStatement pstmt=null;
      try
      {
      Class.forName(drivername);
      conn=(Connection) DriverManager.getConnection(url,username,password);
      conn.setAutoCommit(false);
      String sqlstr="select count(*) from cli_user where username=? and userpass=? and verifycode=? and userstatus=1";
      pstmt=conn.prepareStatement(sqlstr);
      pstmt.setString(1, usrname);
      pstmt.setString(2, thepass);
      pstmt.setString(3, thesecret);
      ResultSet rs=pstmt.executeQuery();
      int theresult=0;
      while(rs.next()) 
      {
     theresult=rs.getInt(1);
      }
         if (theresult==0)
      return -5;
       sqlstr="select privill from cli_user where username=? and userpass=? and verifycode=? ";
      pstmt=conn.prepareStatement(sqlstr);
      pstmt.setString(1, usrname);
      pstmt.setString(2, thepass);
      pstmt.setString(3, thesecret);
      rs=pstmt.executeQuery();
      while(rs.next()) 
      {
     theresult=rs.getInt(1);
      }
    //   if (theresult==null)
    //   theresult=0;
      return theresult;
      
      }
      catch (ClassNotFoundException e) 
      {  
      
      
     return -1;
      }
      catch(SQLException e)
      {
      
     return -2;
      }
      finally
      {
      try {
      if(pstmt!=null)
      pstmt.close();
      }
      catch (Exception e)
      {
    return -4;  
      }
      
      try {
      if (conn != null)
      conn.close();
      }
      catch (Exception e)
      {
      return -4; 
      }
      }
    }}
      

  2.   

    现在由于我不会配置,在TOMCAT里完全是404 无法启用,不知道怎样处理,反正这些代码应该没问题的