用JERSEY写了个REST的API,但不知道该怎样配置,放上源代码码 本帖最后由 ilearn 于 2014-08-19 22:20:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 # 3 secondresource.javaimport 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; } } }} 现在由于我不会配置,在TOMCAT里完全是404 无法启用,不知道怎样处理,反正这些代码应该没问题的 JSF监听器怎么做? jsp帮忙 some characters cannot be mapped using "ISO-8859-1" url路径映射问题,配置文件or servlet?? 各位大人,帮帮小弟我吧 springMVC不返回视图怎么配置 菜鸟问答 如何实现中文附件上传的程序,请赐教!!! 关于JDBC访问数据库的问题,请教高手 servlet重定向问题 纠结了一天了,求大神看看SSH的MYSQL问题 IE下异步提交表单,jquery.form方式没作用
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;
}
}
}}