Over The Air provision - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Over The Air provision

Description:

method='post' postfield name='loginUID' value='$(u)'/ /go /do ... the same URL you used in a browser to test the servlet. ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 20
Provided by: jab88
Category:

less

Transcript and Presenter's Notes

Title: Over The Air provision


1
Over The Air provision
  • Sample files

2
XML files Located on server
Tomcat Servlet engine
Cocoon Handles XML
Servlets can use the Cocoon Parser and
manipulate XML documents
Browser requests UML file
3
Using IIS
xml
Server
xsl
Multiple devices (HTML WML)
4
.jad file sample
  • MIDlet-1 SnowAgent,
  • SnowAgent.png,
  • example.tilepuzzle.SnowMIDlet-Jar-Size 100
  • MIDlet-Jar-URL SnowAgent.jar
  • MIDlet-Name SnowAgent
  • MIDlet-Vendor Sun Microsystems
  • MIDlet-Version 1.0

5
Asp sample
Dim testAgent Dim checkBrowser Dim xmlDocument
Dim xslDocument Set testAgent
Request.ServerVariables("HTTP_USER_AGENT") Set
testmime Request.ServerVariables
("HTTP_ACCEPT") Set checkBrowser
Server.CreateObject("MSWC.BrowserType") Set
xmlDocument Server.CreateObject("Microsoft.XMLDO
M") Set xslDocument Server.CreateObject("Micros
oft.XMLDOM") If ( InStr(testmime,"wml"))Then
Response.ContentType"text/vnd.wap.wml"
Response.Redirect("/student/jab2/newlogin.wml")
Else xmlDocument.load(Server.MapPath("/student/
jab2/index.xml")) xslDocument.load(Server.MapPat
h("/student/jab2/stylesheets/webpage.xsl"))
Response.Write(xmlDocument.transformNode(xslDocu
ment)) End If
6
Servlet sample
import javax.servlet.http. import
javax.servlet.ServletException import
java.io. public class LoginServlet extends
HttpServlet public void doGet(HttpServletReq
uest request, HttpServletResponse response)
throws ServletException, IOException
PrintWriter out response.getWriter()
if (request.getHeader("User-Agent").toLowerCase()
.indexOf("wap") gt 0)
response.setContentType("text/vnd.wap.wml")
out.println(HyperTextUtils.printWmlHead("Lo
gin")) out.println("ltdo
type\"accept\" label\"Login\"gt")
out.println(" ltgo href\"/webApp\"
method\"post\"gt") out.println("
ltpostfield name\"username\" value\"username\"
/gt") out.println(" ltpostfield
name\"password\" value\"password\" /gt")
out.println(" lt/gogt")
out.println("lt/dogt")
out.println("ltpgt") out.println("
Username ltinput type\"text\" name\"username\"
/gtltbr /gt") out.println(" Password
ltinput type\"password\" name\"password\" /gt")
out.println("lt/pgt")
7
Servlet contd
else response.setContentType("text/html")
out.println(HyperTextUtils.printHead("Login"))
out.println("ltform method\"post\"gt")
out.println(" ltttgtUsername lt/ttgtltinput
type\"text\" name\"username\" /gtltbr /gt")
out.println(" ltttgtPassword lt/ttgtltinput
type\"password\" name\"password\" /gt")
out.println("ltinput type\"submit\"
value\"Login\"gt") out.println("lt/formgt")

8
Login using wml
lt?xml version"1.0"?gt lt!DOCTYPE wml PUBLIC
"-//WAPFORUM//DTD WML 1.1//EN" "http//www.wapforu
m.org/DTD/wml_1.1.xml"gt ltwmlgt ltcard id"login"
title"externalsite" newcontext"true"gt ltpgt ltdo
type"accept" label"Login"gt ltgo
href"http//asp.soc.staffs.ac.uk/student/jab2/log
in.asp"

method"post"gt ltpostfield name"loginUID"
value"(u)"/gt lt/gogt lt/dogt username ltinput
type"text" name"u" title"Username" emptyok"f
alse"/gtltbr/gt lta href"http//asp.soc.staffs.ac.uk
/student/jab2/login.asp?loginUID(u)"gt
Loginlt/agt lt/pgt lt/cardgt lt/wmlgt
9
Wml file for download
lt!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML
1.1//EN
"http//www.wapforum.org/DTD/wml_1.1.xml"gt
ltwmlgt ltcard id"card1" title"Hello..."gt ltpgt
go to lta href"SnowAgent.jad"gtSnowlt/agt lt/pgt
lt/cardgt lt/wmlgt
10
Architecture
11

Application Layer WAE Session Layer -
WSP Transaction Layer WTP Security Layer -
WTLS Transport Layer - WDP
12
WAP
  • HTTP/HTML adjusted to small devices
  • Consists of a network architecture,a protocol
    stack and a Wireless Markup Language (WML)
  • For Internet connection a WAP-gateway is required
  • Specifications at http//www.wapforum.org

13
Midlet Servlet connection
  • A servlet extends the capabilities of a web
    server
  • It is possible for a midlet to use the HTTP
    protocol to connect with a servlet
  • The servlet could access a database and return
    results to a mobile device

14
Servlet code
import javax.servlet.http. import
javax.servlet. import java.io. public class
SampleServlet extends HttpServlet private
int nCount public void doGet(HttpServletRequ
est request, HttpServletResponse
response) throws ServletException,
IOException String hits "Hits "
nCount response.setContentType("text/p
lain") response.setContentLength(message
.length()) PrintWriter out
response.getWriter() out.println(message
)

15
Midlet
import java.io.import javax.microedition.io. i
mport javax.microedition.lcdui. import
javax.microedition.midlet. public class
ConnectMIDlet extends MIDlet implements
CommandListener private Display mDisplay
private Form mMainForm private StringItem
mMessageItem private Command ExitCommand,
ConnectCommand public ConnectMIDlet()
mMainForm new Form(ConnectMIDlet")
mMessageItem new StringItem(null,
"") ExitCommand new Command("Exit",
Command.EXIT, 0) ConnectCommand new
Command("Connect", Command.SCREEN, 0)
mMainForm.append(mMessageItem)
mMainForm.addCommand(mExitCommand)
mMainForm.addCommand(mConnectCommand)
mMainForm.setCommandListener(this)
16
Midlet contd
public void startApp() mDisplay
Display.getDisplay(this) mDisplay.setCurrent(
mMainForm) public void pauseApp()
public void destroyApp(boolean unconditional)

17
Command handler
public void commandAction(Command c, Displayable
s) if (c mExitCommand)
notifyDestroyed() else if (c
mConnectCommand) Form waitForm
new Form("Waiting...")
mDisplay.setCurrent(waitForm) Thread
t new Thread()
public void run()

connect()

t.start()
18
connection
private void connect()
HttpConnection hc null InputStream
in null String url
getAppProperty(ConnectMIDlet.URL")
try hc (HttpConnection)Connector.open(url
) in
hc.openInputStream()
int contentLength (int)hc.getLength()
byte raw new
bytecontentLength
int length in.read(raw)
in.close() hc.close()
// Show the response to the user.
String s new String(raw, 0,
length)
mMessageItem.setText(s) catch
(IOException ioe) mMessageItem.setText(ioe.
toString())
mDisplay.setCurrent(mMainForm)
19
Connecting url
Define a system property that ConnectMIDlet uses
as the URL for its network connection. (This
property is retrieved in the third line of the
connect() method.) In the toolkit, click on
Settings..., then select the User Defined tab.
Click on the Add button. Fill in the property
name as ConnectMIDlet.URL the value should be
the URL that invokes HitServlet, the same URL
you used in a browser to test the servlet. When
you're finished, click on OK to dismiss the
project settings window.
Write a Comment
User Comments (0)
About PowerShow.com