小编Mr_*_*s_D的帖子

在JSTL中使用枚举

我正在尝试使用jstl进行一些网站开发,我遇到了以下问题:

在这里,我尝试创建一个下拉列表,其中显示的值是国家/地区名称,值是国家/地区代码.为此,我在后端java代码中有以下枚举:

public static enum CountryCodes implements EnumConstant {
       USA, CAN, AUS, GBR, DEU, ESP, GUM, IND, ISR, MEX, NZL, PAN, PRI;

       public final String toCountry(){
               switch(this){
               case USA:
                       return "United States";
               case CAN:
                       return "Canada";
               case AUS:
                       return "Australia";
               case GBR:
                       return "Great Britan";
               case DEU:
                       return "Germany";
               case ESP:
                       return "Spain";
               case GUM:
                       return "Guam";
               case IND:
                       return "India";
               case ISR:
                       return "Isreal";
               case MEX:
                       return "Mexico";
               case NZL:
                       return "New Zealand";
               case PAN:
                       return "Panama";
               case PRI: …
Run Code Online (Sandbox Code Playgroud)

java jsp jstl

3
推荐指数
1
解决办法
1万
查看次数

Android requestLocationUpdates使用PendingIntent和BroadcastReceiver

我该怎么用

requestLocationUpdates(long minTime, float minDistance, Criteria criteria,
                                                           PendingIntent intent) 
Run Code Online (Sandbox Code Playgroud)

在BroadcastReciver中,我可以继续获取GPS坐标.

我是否必须为LocationListener创建一个单独的类?

我的项目的目标是当我收到BOOT_COMPLETED开始定期获得GPS拉特和长期时.

我试过的代码是:

public class MobileViaNetReceiver extends BroadcastReceiver {

    LocationManager locmgr = null;
    String android_id;
    DbAdapter_GPS db;

    @Override
    public void onReceive(Context context, Intent intent) {
        if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
            startGPS(context);
        } else {
            Log.i("MobileViaNetReceiver", "Received unexpected intent "
                + intent.toString());
        }
    }

    public void startGPS(Context context) {
        Toast.makeText(context, "Waiting for location...", Toast.LENGTH_SHORT)
                .show();
        db = new DbAdapter_GPS(context);
        db.open();
        android_id = Secure.getString(context.getContentResolver(),
                Secure.ANDROID_ID);
        Log.i("MobileViaNetReceiver", "Android id is _ _ _ …
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
1
解决办法
8835
查看次数

使用Context.CONNECTIVITY_SERVICE检查Internet连接

我正在使用此代码检查互联网连接:

private boolean checkInternetConnection() {
    ConnectivityManager cm = (ConnectivityManager)
                              getSystemService(Context.CONNECTIVITY_SERVICE);
    // test for connection
    if (cm.getActiveNetworkInfo() != null
            && cm.getActiveNetworkInfo().isAvailable()
            && cm.getActiveNetworkInfo().isConnected()) {
        return true;
    } else {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

但即使我关闭wifi,它仍然会返回true.

在仿真器和设备上尝试了相同的结果?
怎么了 ?

networking android

3
推荐指数
1
解决办法
2万
查看次数

如何获取相机应用程序的包名称

感谢以前的回复,

是否可以获取设备上安装的摄像头应用程序的包名?如果自定义操作系统,则设备制造商会更改默认包名称.如何通过编码获取包名?我不确定这是可能的.

android

3
推荐指数
2
解决办法
8137
查看次数

通知没有在android中启动活动

我正在开发一个小应用程序,我希望后台服务发送通知,当用户单击通知时,它必须启动相应的活动.我在这里发布通知的代码,我的问题是通知显示在状态栏上但是当我点击它时它不启动活动.有人可以建议我哪里出错了.请帮忙.

NotificationManager notificationManager = (NotificationManager) 
        getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.ic_launcher,
        "A New Message!", System.currentTimeMillis());
Intent notificationIntent = new Intent(NotificationService.this,
        com.jeris.android.MetroActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent pendingIntent = PendingIntent
        .getService(NotificationService.this, 0, notificationIntent,
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(NotificationService.this, "Bullion",
        "Rates for "+ parsedDate+"has not been updated. Go to app to check rates",
        pendingIntent);
notificationManager.notify(11, notification);
Run Code Online (Sandbox Code Playgroud)

service notifications android android-activity

3
推荐指数
1
解决办法
4496
查看次数

eclipse与tomcat部署 - 当项目在eclipse中运行时,导出的war(部分)失败

我在eclipse juno中有一个webapp - 当我在服务器上运行时运行正常 - 在eclipse的浏览器(我在Windows上)或在FF中.

右键单击> 导出war >将其转储到$ CATALINA_HOME/webapps>一切正常(解压缩好了)EXCEPT

  • 我的自定义标签 - 我有一个WEB-INF\functions.tld显然没有读过的文件.自动生成的eclipse server.xml(在Servers项目中)和默认的Tomcat 之间的唯一区别server.xml是:

    <Context docBase="ted2012" path="/ted2012" 
    reloadable="true"source="org.eclipse.jst.jee.server:ted2012"/>
    
    Run Code Online (Sandbox Code Playgroud)

source是WTP特定属性.
我设法解决了 - 看我的答案

  • Tomcat无法正确获取Url - 请参阅我的回答中的图片.

问题:

  1. (未解决)为什么Tomcat没有正确解码Url - 而eclipse呢?失败在哪里?有关调用堆栈的详细信息以及tomcat失败的位置,请参阅我的具体问题
  2. 为什么tomcat在eclipse第一时间没有看到tld?为什么我要编辑web.xml?(在我的回答中解决,应该是另一个问题)

代码在github中 - 在文件INSTRUCTIONS.txt中有详细的说明来设置项目并重现我在下面的答案中描绘的错误.

Tomcat 7.0.32,eclipse 4.2,java 1.7.9

eclipse unicode tomcat java-ee servlet-3.0

3
推荐指数
1
解决办法
1312
查看次数

GPS android requestLocationUpdate

我有一个名为的班级 GPSSampleLocation

有一个功能可以打开gps并根据获取位置

这里gpsEnabled将是真的,但在我的手机中,当我请求gps时,我的电话上方的GPS图标将闪烁......但它也没有闪烁......我没有得到数据

public void getGPSLocation() {
    LocationManager mlocManager = (LocationManager) GPSSampleLocation.this
            .getSystemService(Context.LOCATION_SERVICE);
    boolean gpsEnabled = mlocManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER);
    if (!gpsEnabled) {
        String provider = Settings.Secure.getString(
                getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        if (!provider.contains("gps")) { // if gps is disabled
            final Intent poke = new Intent();
            poke.setClassName("com.android.settings",
                    "com.android.settings.widget.SettingsAppWidgetProvider");
            poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
            poke.setData(Uri.parse("3"));
            sendBroadcast(poke);
        }
    }
    gpsEnabled = mlocManager
            .isProviderEnabled(LocationManager.GPS_PROVIDER);
    System.out.println("GPS ENALBLE" + gpsEnabled);
    if (gpsEnabled) {
        mlocManager.requestLocationUpdates(
                LocationManager.GPS_PROVIDER, 0, 0,
                GPSSampleLocation.this);
    }
}
Run Code Online (Sandbox Code Playgroud)

我也使用了这些权限:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
Run Code Online (Sandbox Code Playgroud)

gps android

3
推荐指数
1
解决办法
4295
查看次数

将registerReceiver用于非活动和非服务类

我试图registerReceiver像BluetoothDevice类的事件ACTION_ACL_CONNECTED,ACTION_ACL_DISCONNECTED.

但是我使用的类registerReceiver不扩展Activity类或Service类 - 所以我传递Context给那个类并按如下方式注册接收器

context.registerReceiver(ActionFoundReceiver, 
          new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED));

context.registerReceiver(ActionFoundReceiver, 
              new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED));

context.registerReceiver(ActionFoundReceiver, 
          new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECT_REQUESTED));
Run Code Online (Sandbox Code Playgroud)

和处理事件如下

private final BroadcastReceiver ActionFoundReceiver = new BroadcastReceiver() {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action)) {
            // do some stuff
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

但是当设备连接或断开连接时我无法跟踪是否意味着ActionFoundReceiver无法调用

android android-service

3
推荐指数
2
解决办法
1万
查看次数

JSF ajax验证与"正常"验证

我有这个小形式,并试图理解在JSF验证中使用ajax.这是表格.(支持bean只是一个带有两个变量firstName和lastName的简单bean.)

<h:form>
    <h:outputLabel for="firstName" value="First Name: " />
    <h:inputText id="firstName" value="#{userBean.firstName}">
        <f:validateLength minimum="5" />
        <f:ajax event="keyup" render="firstNameMsg" />
    </h:inputText>
    <h:message id="firstNameMsg" for="firstName" style="color: red" />
    <br />
    <h:outputLabel for="lastName" value="Last Name: " />
    <h:inputText id="lastName" value="#{userBean.lastName}">
        <f:validateLength minimum="5" />
        <f:ajax event="keyup" render="lastNameMsg" />
    </h:inputText>
    <h:message id="lastNameMsg" for="lastName" style="color: red" />
    <br />
    <h:commandButton value="Submit">
        <f:ajax execute="firstName lastName" render=":greeting" />
    </h:commandButton>
    <br />
</h:form>
<h:outputText id="greeting" value="#{userBean.greeting}" />
Run Code Online (Sandbox Code Playgroud)

我有一个附加到我的按钮的ajax,它在提交时使用名字和姓氏呈现outputText标记,这很好.我的问题是,为什么我需要使用f:ajax标签f:validateLength,以验证这两个领域的标签?我的理解是ajax执行渲染响应阶段的所有生命周期阶段,即它包括验证.无论是否来自ajax请求或常规提交/操作请求,验证阶段是否都不会重新呈现带有消息的页面?如果我删除附加到输入字段的ajax标记,则验证消息不会显示,但如果我完全删除ajax并且只使用commandButtons动作事件使用常规提交,它们就会显示.

谢谢,艾伦

ajax jsf

3
推荐指数
1
解决办法
6193
查看次数

没有找到Class Def Error(android)

我正在开发一个应用程序,我可以启动我的Launcher活动,它有两个按钮.单击任何这些按钮时,应打开一个新活动.但是,会发生运行时错误.


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class Intro extends Activity {

    Button searchBut, fbButton;

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AppSettings.loadLogin(getApplicationContext());
        setContentView(R.layout.intro);
        if (AppSettings.logged) {
            Intent a = new Intent(Intro.this, AllChallengesPager.class);
            a.putExtra("logging", "0");
            startActivity(a);
        }
        searchBut = (Button) findViewById(R.id.button2);
        searchBut.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent a = new Intent(Intro.this, DetailedChallenge.class);
                a.putExtra("logging", "0");
                startActivity(a);
            }
        });
        fbButton = (Button) findViewById(R.id.fbBut);
        fbButton.setOnClickListener(new View.OnClickListener() …
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
1
解决办法
9263
查看次数