1.本人是新手。参考这个文件学习的。http://wenku.baidu.com/link?url=GU54fgSCfP2uiF4nZidG3OQ98al6psBxjN6HQmQ4lN5zGuGUJI-pOMZMGfPYp8Q6AlYDwXOpO7YUBt3YMBKtWHKHo1beBJ3xY1Dqkn-DYYe
2.servlet 文件如下。
/*
HelloServlet.java
*/
package org.mortbay.ijetty.hello;
import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import android.content.ContentResolver;
import android.content.Context;
public class HelloServlet extends HttpServlet {
/**
*
*
*/
private static final long serialVersionUID = 1L;
String proofOfLife = null;
@Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
super.init(config);
Object o = config.getServletContext().getAttribute("org.mortbay.ijetty.contentResolver");
ContentResolver resolver = (ContentResolver)o;
Context androidContext = (Context)config.getServletContext().getAttribute("org.mortbay.ijetty.context");
this.proofOfLife = androidContext.getApplicationInfo().packageName;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String username=req.getParameter("username");
String password=req.getParameter("password");
if("admin".equals(username)&& "123".equals(password))
{
resp.getOutputStream().write("Login susse1".getBytes());;
}else
{
resp.getOutputStream().write("Login error2".getBytes());
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//super.doPost(req, resp);
doGet(req,resp);
}
}
3.web.xml文件如下
/*
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>org.mortbay.ijetty.hello.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/HelloServlet</url-pattern>
</servlet-mapping>
</web-app>
*/
4.dx 结果如下图
5.但是 IE查看如下图