Wednesday, November 14, 2007

doGet()

I wrote my first servlet code in Smart Card Web Server.
Firstly, here is my html code :




Username:





and this following code is part of my servlet code :

public void doGet(HttpCardServletRequest req, HttpCardServletResponse resp)
throws Exception {

try {

ByteString queryString = req.getQueryString();
if (queryString != null) {

byte[] hello = { 'h', 'e', 'l', 'l','o' ,' '};


ByteString temp=queryString.substring((short)5, queryString.length());

// set header
resp.setStatus(HttpCardServletResponse.SC_OK);
resp.setContentType(stringContainer
.getConstantString(HttpStringContainer.TEXT_PLAIN_KEY));

int length = hello.length+temp.length();

resp.setContentLength(length);
// write body

HttpCardServletOutputStream out = resp.getOutputStream();
out.write(hello,(short)0,(short)hello.length);
out.write(temp);

}
} catch (Exception e) {
resp.setStatus(HttpCardServletResponse.SC_BAD_REQUEST);
}

}
This is the capture of the result :

testing by typing such username
Hey, it works now :D

No comments: