各位大大求帮助javaweb+Android
web:
package com.baby.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.baby.bean.Accounts;
import com.baby.biz.AccountsBIZ;
import com.opensymphony.xwork2.ActionSupport;
public class AccountsAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private Accounts account;
public String execute() throws Exception {
HttpServletResponse response=ServletActionContext.getResponse();
HttpServletRequest request=ServletActionContext.getRequest();
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
String name=request.getParameter("name");
String pwd=request.getParameter("pwd");
this.setAccount(new AccountsBIZ().accountLogin(name, pwd));
return SUCCESS;
}
public Accounts getAccount() {
return account;
}
public void setAccount(Accounts account) {
this.account = account;
}
}
accounts略
package com.baby.biz;
import com.baby.bean.Accounts;
import com.baby.dao.AccountsDAO;
public class AccountsBIZ {
public Accounts accountLogin(String name,String pwd){
Accounts account=new AccountsDAO().getUserByName(name);
return account;
}
}
package com.baby.dao;
import org.hibernate.Query;
import org.hibernate.Session;
import com.baby.bean.Accounts;
public class AccountsDAO {
public Accounts getUserByName(String name){
Accounts account=null;
Session session = null;
try{
session = HibernateUtil.getSession();
String hql="from account where name="+name;
Query query = session.createQuery(hql);
account=(Accounts)query.uniqueResult();
}
catch(Exception e){
e.printStackTrace();
}
finally{
HibernateUtil.closeSession(session);
}
return account;
}
}
package com.baby.dao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static SessionFactory factory;
static{
try{
Configuration conf=new Configuration().configure();
factory=conf.buildSessionFactory();
}catch(Exception e){
e.printStackTrace();
}
}
public static SessionFactory getSessionFactory(){
return factory;
}
public static Session getSession(){
return factory.openSession();
}
public static void closeSession(Session session){
if(session!=null){
if(session.isOpen()){
session.close();
}
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<package name="com.baby.action" extends="json-default">
<action name="accountsAction" class="com.baby.action.AccountsAction">
<result type="json" />
</action>
</package>
</struts>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:xe</property>
<property name="connection.username">yt</property>
<property name="connection.password">yt5201220</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="myeclipse.connection.profile">oraclDriver</property>
<mapping resource="com/baby/bean/Users.hbm.xml" />
</session-factory>
</hibernate-configuration>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
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">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>
android:
package com.example.babylearn;
import com.example.dbtool.Baby_L_dbUsercontrol;
import com.example.tool.ConnectWeb;
import com.example.tool.DataShare;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
private Button loginbtn;
private Button registerbtn;
private EditText accountev1_2 = null;
private EditText passwordev1_4 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginbtn = (Button) findViewById(R.id.loginbtn);
registerbtn = (Button) findViewById(R.id.registerbtn);
accountev1_2 = (EditText) findViewById(R.id.accountev1_2);
passwordev1_4 = (EditText) findViewById(R.id.passwordev1_4);
loginbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
account theuser=new ConnectWeb().userLogin(accountev1_2.getText().toString(),passwordev1_4.getText().toString());
if(theuser!=null){
// DataShare.user.setId(theuser.getId());//设置用户id
// DataShare.user.setAname(theuser.getAname());//设置用户昵称
// DataShare.user.setUserPwd(theuser.getUserPwd());//设置用户密码
// Toast.makeText(ViewLogin.this, "登录成功", Toast.LENGTH_LONG).show();
// //登录成功后进入购物车
Toast toast=Toast.makeText(MainActivity.this, "登陆成功",
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
Intent intent = new Intent();
intent.setClass(MainActivity.this, MainInterface.class);
startActivity(intent);
}else{
Toast toast=Toast.makeText(MainActivity.this, "登陆失败",
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
Intent intent = new Intent();
intent.setClass(MainActivity.this, Register.class);
startActivity(intent);
}
}
});
registerbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MainActivity.this, Register.class);
startActivity(intent);
finish();
}
});
}
}
package com.example.tool;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;
import com.example.babylearn.account;
public class ConnectWeb {
public static String path = "http://localhost:8888/BabyLearnWeb/";
private String connWeb(String url) {
String str = "";
try {
HttpGet request = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
if (response.getStatusLine().getStatusCode() == 200) {
str = EntityUtils.toString(response.getEntity());
}
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
public account userLogin(String aname, String pwd) {
account account = null;
String url = path + "usersAction.action?aname=" + aname + "&pwd="
+ pwd;
String str = connWeb(url);
try {
JSONObject job = new JSONObject(str);
JSONObject job2 = (JSONObject) job.get("account");
account = new account();
account.setId(job2.getInt("id"));
account.setAname(job2.getString("aname"));
account.setUserPwd(job2.getString("pwd"));
System.out.println("aaa:" + job.getInt("id") + ","
+ job.getString("aname") + "," + job.getString("pwd"));
} catch (Exception e) {
e.printStackTrace();
}
return account;
}
}
相关推荐
android图书管理系统+javaweb后台服务器代码
android图书管理系统+javaweb后台服务器代码+数据库建表语句
从嵌入式开发到 android 开发再到 javaWeb 开发
“今天在网上看到一则段子:一位去年8月加入百度外卖的员工诉苦道,’我先是百度员工,然后是饿了么员工,现在又变成阿里员工了,可我明明什么都没有做啊。’ - -keithxiaoy” 这个段子的由来一则资讯:一名接近阿里的人士确认阿里巴巴全资收购饿了么一事属实,但是传言的95亿美元收购的金额不实,据悉,阿里巴巴旗下的口碑平台将与饿了么合并。原因可能为阿里和饿了么签订的对赌协议,要求饿了么在2...
安卓+javaWeb
安卓+javaWeb
Android应用源码基于安卓的校园二手交易系统
Android应用源码基于安卓的校园二手交易系统客户端+服务端+数据库源码免费下载。本项目是一个基于安卓和javaweb的校园二手交易系统, 包括整套安卓客户端、javaweb服务端、mysql数据库,可以进行基本的列表显示帖子、显示帖子详情、用户注册登录、收藏帖子、留言、上传图片发布信息,管理发布的帖子、发布和管理求购信息等交易系统常见的功能。 机子上有myeclipse的朋友可以直接导入项目,配合mysql数据库进行测试, 没有myeclipse的朋友可以搜一个叫jspstudy 2014的jsp集成环境进行测试, mysql连接地址需要在web端src下的jdbc.properties中替换,安卓客户端连接web的地址在com.yhx.app.common包下的Constants.java中替换, 因为我电脑有点问题就没有搭建环境进行完整的测试,截图是在没有连接服务端的情况下测试的,需要的朋友可以自己链接好数据库和服务端看一下, 注意本项目有依赖库,导入的时候需要把安卓客户端和依赖库一起导入进去,如果提示有问题需要在Library里面设置好引用关系。项目有大量注释默认编译版本4.2.2编码UTF-8。 更多源码下载: 捡代码论坛:bbs.jiandaima.com
Android应用源码基于安卓的校园二手交易系统客户端+服务端+数据库.rar
Android应用源码基于安卓的校园二手交易系统客户端+服务端+数据库 代码非常全,有手机客户端,还有电脑服务器端,可以说是一个很完整的Android项目,大家可以参考下,大学里面可以做项目参加比赛的。。


高性能WEB开发
