03-11-2013 01:23 AM
<div id="${el}-body" class="password">
<form id="${el}-form" action="${url.context}/service/formhandle" method="post">
<div class="header-bar">${msg("label.title")}</div>
<div class="row">
<span class="label"><label for="${el}-username">${msg("label.username")}:</label></span>
<span class="input"><input type="text" maxlength="255" size="30" id="${el}-username" /></span>
</div>
<div class="row">
<span class="label"><label for="${el}-password">${msg("label.password")}:</label></span>
<span class="input"><input type="password" maxlength="255" size="30" id="${el}-password" /></span>
</div>
<form>
</div>
public class SimpleWebScript extends AbstractWebScript
{
public void execute(WebScriptRequest req, WebScriptResponse res)
throws IOException
{
try
{
String[] params = req.getParameterNames();
String errormsg = "";
String mess = "fail";
for(int i = 0; i < params.length; i++){
errormsg += params;
errormsg += "*";
}
// build a json object
JSONObject obj = new JSONObject();
// put some data on it
obj.put("success", false);
if(params.length == 0)
obj.put("message", fail);
else
obj.put("message", errormsg);
// build a JSON string and send it back
String jsonString = obj.toString();
res.getWriter().write(jsonString);
}
catch(JSONException e)
{
throw new WebScriptException("Unable to serialize JSON");
}
}
}
03-11-2013 01:41 AM
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
Map<String,Object> model = new HashMap<String, Object>();
Content c = req.getContent();
if (c == null)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Missing POST body.");
}
// Process the JSON
JSONParser parser = new JSONParser();
JSONObject json = null;
try
{
Reader reader = req.getContent().getReader();
Object jsonO = null;
if (reader.ready())
{
jsonO = parser.parse(req.getContent().getReader());
}
if (jsonO instanceof JSONObject && jsonO != null)
{
json = (JSONObject)jsonO;
}
else
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Wrong JSON type found " + jsonO);
}
}
catch(ParseException pe)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Invalid JSON data received", pe);
}
catch(IOException ioe)
{
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Error while reading JSON data", ioe);
}
///…………………… Your code goes here …………………….
}
03-12-2013 01:26 PM
JSONObject json = null;
Object jsonO = req.parseContent();
if (jsonO instanceof JSONObject && jsonO != null)
{
json = (JSONObject)jsonO;
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.