解决方案 »
- 无法从tomcat下载文件
- 很简单的问题 这个值怎么传过来?
- android 游戏中怎么根据图片的路径加载到程序中
- Android2.3开发环境用32位和64位有要求么?
- android marquee 跑完之后,自动隐藏
- 音乐播放error
- 关于在Eclipse3.6中新建一个Android项目失败的问题
- android原生的camera程序:由pause()再回到resume()时,右侧会显示一下title 。
- xmlPullParser 的setInput()方法参数问题~~求解
- listview 刷新问题,小弟新手,找了很多都没弄懂,
- 如何布置这个布局?
- 大神救命啊!64位ubuntu下用Android Screen Monitor 报错!
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.RequestMapping;
import com.taocaiku.gaea.common.web.annotation.AndroidDontLogin;
import com.taocaiku.pages.util.ToolUtil;/**
* 安卓接口的servlet
* @author TCK-001
* @version 1.0
*/
@SuppressWarnings({ "rawtypes", "unchecked", "serial" })
public class ControlServlet extends HttpServlet {
/**
* 初始化servlet
* */
@Override
public void init() throws ServletException {
String classPath = ToolUtil.getClasspath();
String packArr[] = new String[] { "com.taocaiku.pages.web.controller.android" };
for (int i = 0; i < packArr.length; i++) {
File folder = new File(classPath + getPackagePath(packArr[i]));
File[] files = folder.listFiles();
for (File file : files) {
if (file.isFile()) {
String fileName = file.getName();
if (fileName.indexOf(".") != -1 && ".class".equals(fileName.substring(fileName.lastIndexOf(".")))) {
String clazz = packArr[i] + "." + fileName.substring(0, fileName.lastIndexOf("."));
Class class1 = null;try {class1 = Class.forName(clazz);} catch (Exception e) {}
if (null != class1 && null != class1.getAnnotation(RequestMapping.class)) {// 如果是control
RequestMapping mapping = (RequestMapping) class1.getAnnotation(RequestMapping.class);
String controlName = mapping.value()[0];
if (null != BeanManager.getControl(controlName)) {// control的名称不能重复
throw new ServletException("control名称[" + controlName + "]不能被重复声明");
}
ControlBean bean = new ControlBean();
bean.setControlClass(class1);
bean.setMethods(loadMethod(class1));
BeanManager.setControl(controlName, bean);
}
}
}
}
}
}
/**
* 加载Control中的方法
* @param class1
* @return
* @throws ServletException
*/
private Map<String, ControlBean.InnerMethod> loadMethod(Class class1) throws ServletException {
Map<String, ControlBean.InnerMethod> innerMethods = new HashMap<String, ControlBean.InnerMethod>();
Method[] methods = class1.getMethods();
for (Method method : methods) {
if (null != method.getAnnotation(RequestMapping.class) && method.getParameterTypes().length == 0) {
RequestMapping mapping1 = (RequestMapping) method.getAnnotation(RequestMapping.class);
String methodKey = mapping1.value()[0];
if (null != innerMethods.get(methodKey)) {
throw new ServletException("方法映射名称[" + methodKey + "]不能被重复声明");
}
ControlBean.InnerMethod innerMethod = new ControlBean.InnerMethod();
innerMethod.setName(method.getName());
if (null != mapping1.method() && mapping1.method().length > 0) {
innerMethod.setMethod(mapping1.method()[0].toString());
}
boolean isLogin = (null == class1.getAnnotation(AndroidDontLogin.class) && null == method.getAnnotation(AndroidDontLogin.class));
innerMethod.setIsLogin(isLogin);
innerMethods.put(methodKey, innerMethod);
}
}
return innerMethods;
}
/**
* 处理get请求
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
CenterControl.getBean().execute(request, response);
} /**
* 处理post请求
* @param request
* @param response
* @throws ServletException
* @throws IOException
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
/**
* 根据包名获得相对路径
* @param packageName 包名
* @return String
*/
private String getPackagePath(String packageName) {
String result = "";
String []array = packageName.split("\\.");
for (int i = 0; i < array.length; i++) {
result += File.separator + array[i];
}
return result + File.separator;
}}
import java.util.Map;import org.json.JSONArray;import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.EditText;import com.taocaiku.gaea.Config;
import com.taocaiku.gaea.R;
import com.taocaiku.gaea.activity.pilot.MyAct;
import com.taocaiku.gaea.common.activity.AbstractActivity;
import com.taocaiku.gaea.domain.Domain;
import com.taocaiku.gaea.domain.Json;
import com.taocaiku.gaea.domain.Member;
import com.taocaiku.gaea.domain.context.Container;
import com.taocaiku.gaea.domain.context.OtherUrls;
import com.taocaiku.gaea.domain.context.TckUrls;
import com.taocaiku.gaea.service.UpdaterService;
import com.taocaiku.gaea.util.BrowserUtil;/**
*
* 登录界面
*
* @author TCK-001
* @version 1.0
*/
@SuppressLint({ "HandlerLeak", "SetJavaScriptEnabled" })
@SuppressWarnings({ "rawtypes", "unchecked" })
public class LoginAct extends AbstractActivity { /** 视图组件 */
private EditText txtName, txtPwd; /** 视图组件 */
private WebView webview; /**
* 垃圾回收
* */
@Override
public void clearData() {
super.clearObjectData();
txtName = null;
txtPwd = null;
webview = null;
} /**
* 界面初始化
*
* @param bundle
* */
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.outer_login);
setTopTitle(true, getString(R.string.login), null, true);
txtName = findView(R.id.txtName);
txtPwd = findView(R.id.txtPwd);
setUserInput();
initBrowser();
viewUtil.hideKeyboard(this);
} /**
* 初始化内嵌浏览器
* */
private void initBrowser() {
webview = findView(R.id.wbvBrowser);
Map<String, Object> gressMsg = toolUtil.createMap(new String[] {
OtherUrls.QQ_LOGIN_URL, OtherUrls.SINA_LOGIN_URL,
Config.TCK_DOMAIN + "/check/third.htm" }, new Object[] {
"正在加载QQ界面...", "正在加载新浪微博界面...", "正在登录淘材库服务器..." });
BrowserUtil.get(webview, "otherLogin.showBrowserSource", gressMsg,
false);
webview.addJavascriptInterface(this, "otherLogin");
} /**
* 登录
*
* @param view
*/
public void doLogin(View view) {
if (notNull(getText(txtName), "用户名", true, txtName)
&& notNull(getText(txtPwd), "密码", true, txtPwd)) {
try {
Map<String, Object> param = toolUtil.createMap(new String[] {
"name", "pwd" }, new Object[] { getText(txtName),
toolUtil.toUnicode(getText(txtPwd)) });
webUtil.setRequestParam(Domain.LONG_REQUEST_TIME,
TckUrls.LOGIN_URL, false);
requestTck(param, GRESS_COMMIT_MSG, "callback", false, true,
false);
} catch (Exception e) {
prompt(OP_ERROR_MSG);
}
}
} /**
* 登录的回调
* */
public void callback() {
try {
resultJson.addData("member", beanUtil.jsonToBean(
resultJson.getKeyData("member"), Member.class));
resetMemberFile(getText(txtName), getText(txtPwd));
UpdaterService.get()
.initMap(
new JSONArray(resultJson.getKeyData("updaters")
.toString()));
toBack(null);
} catch (Exception e) {
prompt(OP_ERROR_MSG);
}
} /**
* 去注册
*
* @param view
*/
public void toReg(View view) {
changeAct(RegisterAct.class, null, Domain.LEFT);
} /**
* 去找回密码
*
* @param view
*/
public void toFind(View view) {
changeAct(FindPwdAct.class, null, Domain.LEFT);
} /**
* 后退按钮
*
* @param view
* */
@Override
public void toBack(View view) {
Class last = getParam("lastActivity");
Map<String, Object> map = (null != last
&& null != getParam("lastParam") ? (Map<String, Object>) getParam("lastParam")
: null);
changeAct(null == last ? MyAct.class : last, map, null);
} /**
* 加载保存在sd卡中的用户名和密码
* */
private void setUserInput() {
Member member = null;
try {
member = fileUtil.turnSerialize(fileUtil.getContextRoot()
+ Domain.MEMOR_FILE);
} catch (Exception e) {
}
if (null != member) {
txtName.setText(member.getName());
txtPwd.setText(member.getPasswd());
}
} /**
* qq登录
*
* @param view
*/
public void qqLogin(View view) {
if (!Container.pingTck || !webUtil.isNet()) {
prompt(!webUtil.isNet() ? NET_ERR_MSG : OP_ERROR_MSG);
return;
}
if (Config.TCK_IP.indexOf("taocaiku") == -1) {
prompt("测试环境下, 该功能不可用");
return;
}
findView(R.id.lltContent).setVisibility(View.GONE);
webview.loadUrl(OtherUrls.QQ_LOGIN_URL
+ "?response_type=code&client_id=" + Domain.QQ_ID
+ "&redirect_uri="
+ OtherUrls.YIMARK_URL.replace("http://", "") + "&state=TCK"
+ Domain.QQ + "," + Domain.ANDROID);
} /**
* 第三方登录的回调
*
* @param code
* @param type
* @param memberJson
* @param updatersJson
*/
public void otherLoginCallback(String code, String type, String memberJson,
String updatersJson) {
try {
Container.otherLoginType = type;
resultJson = new Json(true).addData("member",
beanUtil.jsonToBean(memberJson, Member.class));
resetMemberFile(null, null);
UpdaterService.get().initMap(new JSONArray(updatersJson));
toBack(null);
} catch (Exception e) {
prompt(OP_ERROR_MSG);
}
} /**
* 微博登录
*
* @param view
*/
public void wbLogin(View view) {
if (!Container.pingTck || !webUtil.isNet()) {
prompt(!webUtil.isNet() ? NET_ERR_MSG : OP_ERROR_MSG);
return;
}
if (Config.TCK_IP.indexOf("taocaiku") == -1) {
prompt("测试环境下, 该功能不可用");
return;
}
findView(R.id.lltContent).setVisibility(View.GONE);
webview.loadUrl(OtherUrls.SINA_LOGIN_URL + "?client_id=" + Domain.WB_ID
+ "&response_type=code&redirect_uri=" + OtherUrls.YIMARK_URL
+ "&state=TCK" + Domain.WB + "," + Domain.ANDROID);
} /**
* 显示webview的源代码
*
* @param html
*/
public void showBrowserSource(String html) {
System.out.println(html);
}}