我正在尝试使用Volley库从Android设备向数据库发送一些信息。通过jsp脚本在服务器上接收信息,并且在接收时我需要提取值并使用Java Bean来更新数据库。 我已经使用了一个JSONObject,如我的jsp代码所示,但我最终找到了一个未找到符号的错误"。有人可以指出我出错的地方或举一个使用jsp的凌空的例子。
Java代码
private void registerMember(final String IDNo, final String NHIFNo, final String Email, final String MobileNo, final String Password, final String ConfPassword){
//startActivity(new Intent(Register.this,LoginActivity.class));
pDialog.show();
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST, Links.register, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
pDialog.dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (error == null || error.networkResponse == null) {
return;
}
String body="";
//get status code here
final String statusCode = String.valueOf(error.networkResponse.statusCode);
//get response body and parse with appropriate encoding
try {
body = new String(error.networkResponse.data,"UTF-8");
} catch (UnsupportedEncodingException e) {
// exception
}
Log.d(TAG2, body+" code "+statusCode);
pDialog.dismiss();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("IDNo", IDNo);
params.put("NHIFNo", NHIFNo);
params.put("Email", Email);
params.put("MobileNo", MobileNo);
params.put("Password", Password);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
}
然后JSP代码
<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<jsp:useBean id="sessionBean" scope="session" class="com.ngenx.edms.SessionBean"></jsp:useBean>
<jsp:useBean id="mailBean" scope="session" class="com.ngenx.edms.Mail.EMailBean"></jsp:useBean>
<jsp:useBean id="registryBean" scope="session" class="com.ngenx.edms.Registry.RegistryBean"></jsp:useBean>
<jsp:useBean id="applicationLevelBean" scope="session" class="com.ngenx.edms.ApplicationLevel"></jsp:useBean>
<jsp:useBean id="systemPropertiesBean" scope="application" class="com.ngenx.edms.System.SystemPropertiesBean"></jsp:useBean>
<jsp:useBean id="membersBean" scope="session" class="com.ngenx.ehmis.Members.MembersBean"></jsp:useBean>
<jsp:useBean id="registerMember" scope="session" class="com.ngenx.Android.RegisterMember"></jsp:useBean>
<%@page import="java.io.*"%>
<%@page import="java.sql.*"%>
<%@page import="java.text.*"%>
<%@page import="com.oreilly.servlet.*"%>
<%@page import="com.oreilly.servlet.multipart.*"%>
<%@page import="org.json.JSONObject.*"%>
<%@page import="java.util.Iterator"%>
<%
try{
String idNo = "";
String nfNo = "";
String email = "";
String mobileNo = "";
String password = "";
// this parses the json
System.out.println("REQ_PARAM "+request.getParameter("params"));
JSONObject jObj = new JSONObject(request.getParameter("params"));
Iterator it = jObj.keys(); //gets all the keys
while(it.hasNext())
{
String key = it.next(); // get key
if(key.equals("IDNo")){
idNo=jObj.get(key);
}else if(key.equals("NFNo")){
nfNo=jObj.get(key);
}else if(key.equals("Email")){
email=jObj.get(key);
}else if(key.equals("MobileNo")){
mobileNo=jObj.get(key);
}else if(key.equals("Password")){
password=jObj.get(key);
}
}//end of while
if(registerMember.memberRegistration(idNo,nhNo,email,mobileNo,password)){
JSONObject json = new JSONObject();
json.put("Registering", "Successful");
response.setContentType("application/json");
response.getWriter().write(json.toString());
}
}catch(Exception e){
out.print("A general error was realised.<br>"+e.getMessage());
action = "register";
}
%>
服务器日志跟踪
PWC6197: An error occurred at line: 16 in the jsp file: /registerMember.jsp
PWC6199: Generated servlet error:
cannot find symbol
symbol: class JSONObject
location: class org.apache.jsp.registerMember_jsp
PWC6197: An error occurred at line: 16 in the jsp file: /registerMember.jsp
PWC6199: Generated servlet error:
cannot find symbol
symbol: class JSONObject
location: class org.apache.jsp.registerMember_jsp
PWC6197: An error occurred at line: 16 in the jsp file: /registerMember.jsp
PWC6199: Generated servlet error:
incompatible types: java.lang.Object cannot be converted to java.lang.String
PWC6197: An error occurred at line: 16 in the jsp file: /registerMember.jsp
PWC6199: Generated servlet error:
cannot find symbol
symbol: class JSONObject
location: class org.apache.jsp.registerMember_jsp
PWC6197: An error occurred at line: 16 in the jsp file: /registerMember.jsp
PWC6199: Generated servlet error:
cannot find symbol
symbol: class JSONObject
location: class org.apache.jsp.registerMember_jsp
PWC6197: An error occurred at line: 16 in the jsp file: /registerMember.jsp
PWC6199: Generated servlet error:
cannot find symbol
symbol: variable action
location: class org.apache.jsp.registerMember_jsp
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:129)
at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:299)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:392)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:791)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1580)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:258)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:652)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:591)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:371)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:238)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:460)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:168)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:242)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:593)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:573)
at java.lang.Thread.run(Thread.java:748)
]]