问:
Property 'driverClassName' threw exception; Could not load JDBC driver class [org.postgresql.Driver]
I am a beginner to Spring

I was trying to test my connection to database(postgresql) and thus wrote following simple piece of code. But it is throwing this error which i am not able to resolve.

Error thrown:

```<code>Jul 05, 2017 12:01:13 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4534b60d: startup date [Wed Jul 05 12:01:13 IST 2017]; root of context hierarchy
Jul 05, 2017 12:01:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Jul 05, 2017 12:01:14 PM org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.javatpoint.Test.main(Test.java:9)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1510)
    ... 13 more

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.javatpoint.Test.main(Test.java:9)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1510)
    ... 13 more
</code>```

My main class is Employee.java :

```<code>package com.javatpoint;

public class Employee {
    private int id;
    private String name;
    private float salary;

    public Employee() {
    }

    public Employee(int id, String name, float salary) {
        super();
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getSalary() {
        return salary;
    }

    public void setSalary(float salary) {
        this.salary = salary;
    }

}
</code>```

My Dao file is EmployeeDao.java :

```<code>package com.javatpoint;
import org.springframework.jdbc.core.JdbcTemplate;

public class EmployeeDao {
private JdbcTemplate jdbcTemplate;

public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
}

public int saveEmployee(Employee e){
    String query="insert into employee values('"+e.getId()+"','"+e.getName()+"','"+e.getSalary()+"')";
    return jdbcTemplate.update(query);
}
public int updateEmployee(Employee e){
    String query="update employee set name='"+e.getName()+"',salary='"+e.getSalary()+"' where id='"+e.getId()+"' ";
    return jdbcTemplate.update(query);
}
public int deleteEmployee(Employee e){
    String query="delete from employee where id='"+e.getId()+"' ";
    return jdbcTemplate.update(query);
}

}
</code>```

My xml file is applicationContext.xml :

```<code><?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/Testing" />
<property name="username" value="postgres" />
<property name="password" value="hlinaknk" />
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>

<bean id="edao" class="com.javatpoint.EmployeeDao">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>

</beans>
</code>```

And my test file is Test.java :

```<code>package com.javatpoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {

    public static void main(String[] args) {

        ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");

        EmployeeDao dao=(EmployeeDao)ctx.getBean("edao");

        try {
              Class.forName("org.postgresql.Driver");
              //on classpath
            } catch(ClassNotFoundException e) {
              // not on classpath
            }

        int status=dao.saveEmployee(new Employee(102,"Amit",35000));
        System.out.println(status);

        /*int status=dao.updateEmployee(new Employee(102,"Sonoo",15000));
        System.out.println(status);
        */

        /*Employee e=new Employee();
        e.setId(102);
        int status=dao.deleteEmployee(e);
        System.out.println(status);*/

    }

}
</code>```

Can anyone please suggest what is going on wrong here?

答:
You got this error popping up:

```<code>PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
</code>```

Test if "org.postgresql.Driver" is on your classpath like so:

```<code>try {
  Class.forName("org.postgresql.Driver");
  //on classpath
} catch(ClassNotFoundException e) {
  //not on classpath
}
</code>```

You might wanna read this question: getting error: Could not load JDBC driver class [org.postgresql.Driver]

Body:
I am a beginner to Spring

I was trying to test my connection to database(postgresql) and thus wrote following simple piece of code. But it is throwing this error which i am not able to resolve.

Error thrown:

Jul 05, 2017 12:01:13 PM org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@4534b60d: startup date [Wed Jul 05 12:01:13 IST 2017]; root of context hierarchy
Jul 05, 2017 12:01:14 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Jul 05, 2017 12:01:14 PM org.springframework.context.support.ClassPathXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.javatpoint.Test.main(Test.java:9)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1510)
    ... 13 more

Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at com.javatpoint.Test.main(Test.java:9)
Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:121)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1510)
    ... 13 more

My main class is Employee.java :

package com.javatpoint;

public class Employee {
    private int id;
    private String name;
    private float salary;

    public Employee() {
    }

    public Employee(int id, String name, float salary) {
        super();
        this.id = id;
        this.name = name;
        this.salary = salary;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public float getSalary() {
        return salary;
    }

    public void setSalary(float salary) {
        this.salary = salary;
    }

}

My Dao file is EmployeeDao.java :

package com.javatpoint;
import org.springframework.jdbc.core.JdbcTemplate;

public class EmployeeDao {
private JdbcTemplate jdbcTemplate;

public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
}

public int saveEmployee(Employee e){
    String query="insert into employee values('"+e.getId()+"','"+e.getName()+"','"+e.getSalary()+"')";
    return jdbcTemplate.update(query);
}
public int updateEmployee(Employee e){
    String query="update employee set name='"+e.getName()+"',salary='"+e.getSalary()+"' where id='"+e.getId()+"' ";
    return jdbcTemplate.update(query);
}
public int deleteEmployee(Employee e){
    String query="delete from employee where id='"+e.getId()+"' ";
    return jdbcTemplate.update(query);
}

}

My xml file is applicationContext.xml :

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5432/Testing" />
<property name="username" value="postgres" />
<property name="password" value="hlinaknk" />
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>

<bean id="edao" class="com.javatpoint.EmployeeDao">
<property name="jdbcTemplate" ref="jdbcTemplate"></property>
</bean>

</beans>

And my test file is Test.java :

package com.javatpoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {

    public static void main(String[] args) {

        ApplicationContext ctx=new ClassPathXmlApplicationContext("applicationContext.xml");

        EmployeeDao dao=(EmployeeDao)ctx.getBean("edao");

        try {
              Class.forName("org.postgresql.Driver");
              //on classpath
            } catch(ClassNotFoundException e) {
              // not on classpath
            }

        int status=dao.saveEmployee(new Employee(102,"Amit",35000));
        System.out.println(status);

        /*int status=dao.updateEmployee(new Employee(102,"Sonoo",15000));
        System.out.println(status);
        */

        /*Employee e=new Employee();
        e.setId(102);
        int status=dao.deleteEmployee(e);
        System.out.println(status);*/

    }

}

Can anyone please suggest what is going on wrong here?

Body:
You got this error popping up:

PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception; nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [org.postgresql.Driver]

Test if "org.postgresql.Driver" is on your classpath like so:

try {
  Class.forName("org.postgresql.Driver");
  //on classpath
} catch(ClassNotFoundException e) {
  //not on classpath
}

You might wanna read this question: getting error: Could not load JDBC driver class [org.postgresql.Driver]


来源: stackexchange

问:
how i can get onActivityResult in fragment from secondActivity
from fragment i started FirstActivity  and from FirstActivity i started a SecondActivity.how i can get onActivityResult in fragment from SecondActivity.
I tried to Add android:noHistory="true" in firstActivity.

is there a way to achieve this?
Thanks in advance

FragmentActivity

```<code>@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    hotelImageMain.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent(myContext, HotelsByLocation.class);
        intent.putExtra(HotelActivity.EXTRA_PARAM_FOR_RESULT, true);
        intent.putExtra(HotelsByLocation.EXTRA_PARAM_LOCATION_NAME, App.getInstance().getDayList().get(AddHotels.viewPager.getCurrentItem()).get(App.HASHMAP_PARA_CITY_NAME));
        intent.putExtra(HotelsByLocation.EXTRA_PARAM_LOCATION_ID, App.getInstance().getDayList().get(AddHotels.viewPager.getCurrentItem()).get(App.HASHMAP_PARA_CITY_ID));
        startActivityForResult(intent, MY_REQUEST_CODE_TWO);
     }
 });

@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);

      if (requestCode == MY_REQUEST_CODE_TWO) {
                  if (resultCode == Activity.RESULT_OK) {
                      Toast.makeText(myContext, "Welcome Back from HotelsByLocation", Toast.LENGTH_SHORT).show();
                      HashMap<String, String> map = new HashMap<String, String>();
                      map.put(App.HASHMAP_PARA_CITY_NAME, data.getStringExtra("cname"));
                      map.put(App.HASHMAP_PARA_CITY_ID, data.getStringExtra("cid"));
                      map.put(App.HASHMAP_PARA_HOTEL_NAME, data.getStringExtra("name"));
                      map.put(App.HASHMAP_PARA_HOTEL_IMAGE, data.getStringExtra("img"));
                      App.getInstance().getDayList().set(AddHotels.viewPager.getCurrentItem(),map);
                      hotel_name_main.setText(data.getStringExtra("name"));
                      Picasso.with(myContext)
                              .load(data.getStringExtra("img"))
                              .error(R.drawable.ic_empty)
                              .placeholder(R.drawable.ic_empty)
                              .into(hotelImageMain);

      }
      } else if (resultCode == Activity.RESULT_CANCELED) {
          // some stuff that will happen if there's no result
          Toast.makeText(myContext, "you haven't selected", Toast.LENGTH_SHORT).show();
      }
  }
</code>```

FirstActivity

```<code>mmAdapter.setOnItemClickListener(new HATwo.OnItemClickListener() {
    @Override
    public void onItemClick(View view, int position) {
       Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
       intent.putExtra(MyActivity.EXTRA_PARAM_HOTEL_ID, mPhotosList.get(position).getId());
       intent.putExtra(MyActivity.EXTRA_PARAM_HOTEL_NAME, mPhotosList.get(position).getTitle());
       intent.putExtra(HotelActivity.EXTRA_PARAM_FOR_RESULT, true);
      //startActivityForResult(intent, MY_REQUEST_CODE_TWO);
       startActivity(intent);
</code>```

SecondActivity

```<code>public void onClick(View v) {
    Intent intent = new Intent();
    intent.putExtra("name",nameOfTheHotel );
    intent.putExtra("id", hotelId);
    setResult(Activity.RESULT_OK, intent);
    finish();
}
</code>```

答: You might want to use startActivity from fragment to firstactivity and then startActivityForResult from firstactivity to secondactivity.  When you get your result from secondactivity you handle it on your firstactivity's onActivityResultResult and use intent to go from firstactivity to the fragment and pass the value obtained from second activity to fragment from firstactivity.  make sure to handle the backstack correctly.</p>

ContentLicense: CC BY-SA 3.0

Body:
from fragment i started FirstActivity  and from FirstActivity i started a SecondActivity.how i can get onActivityResult in fragment from SecondActivity.
I tried to Add android:noHistory="true" in firstActivity.

is there a way to achieve this?
Thanks in advance

FragmentActivity

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    hotelImageMain.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Intent intent = new Intent(myContext, HotelsByLocation.class);
        intent.putExtra(HotelActivity.EXTRA_PARAM_FOR_RESULT, true);
        intent.putExtra(HotelsByLocation.EXTRA_PARAM_LOCATION_NAME, App.getInstance().getDayList().get(AddHotels.viewPager.getCurrentItem()).get(App.HASHMAP_PARA_CITY_NAME));
        intent.putExtra(HotelsByLocation.EXTRA_PARAM_LOCATION_ID, App.getInstance().getDayList().get(AddHotels.viewPager.getCurrentItem()).get(App.HASHMAP_PARA_CITY_ID));
        startActivityForResult(intent, MY_REQUEST_CODE_TWO);
     }
 });

@Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);

      if (requestCode == MY_REQUEST_CODE_TWO) {
                  if (resultCode == Activity.RESULT_OK) {
                      Toast.makeText(myContext, "Welcome Back from HotelsByLocation", Toast.LENGTH_SHORT).show();
                      HashMap<String, String> map = new HashMap<String, String>();
                      map.put(App.HASHMAP_PARA_CITY_NAME, data.getStringExtra("cname"));
                      map.put(App.HASHMAP_PARA_CITY_ID, data.getStringExtra("cid"));
                      map.put(App.HASHMAP_PARA_HOTEL_NAME, data.getStringExtra("name"));
                      map.put(App.HASHMAP_PARA_HOTEL_IMAGE, data.getStringExtra("img"));
                      App.getInstance().getDayList().set(AddHotels.viewPager.getCurrentItem(),map);
                      hotel_name_main.setText(data.getStringExtra("name"));
                      Picasso.with(myContext)
                              .load(data.getStringExtra("img"))
                              .error(R.drawable.ic_empty)
                              .placeholder(R.drawable.ic_empty)
                              .into(hotelImageMain);

      }
      } else if (resultCode == Activity.RESULT_CANCELED) {
          // some stuff that will happen if there's no result
          Toast.makeText(myContext, "you haven't selected", Toast.LENGTH_SHORT).show();
      }
  }

FirstActivity

mmAdapter.setOnItemClickListener(new HATwo.OnItemClickListener() {
    @Override
    public void onItemClick(View view, int position) {
       Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
       intent.putExtra(MyActivity.EXTRA_PARAM_HOTEL_ID, mPhotosList.get(position).getId());
       intent.putExtra(MyActivity.EXTRA_PARAM_HOTEL_NAME, mPhotosList.get(position).getTitle());
       intent.putExtra(HotelActivity.EXTRA_PARAM_FOR_RESULT, true);
      //startActivityForResult(intent, MY_REQUEST_CODE_TWO);
       startActivity(intent);

SecondActivity

public void onClick(View v) {
    Intent intent = new Intent();
    intent.putExtra("name",nameOfTheHotel );
    intent.putExtra("id", hotelId);
    setResult(Activity.RESULT_OK, intent);
    finish();
}


问:
launch google maps in IOS with multiple waypoints
I need to launch google maps with multiple waypoint showing on map on IOS using url in my Xamarin forms application.
I'm able to launch it with 2 points (Source and Destination) using this url:

```<code>comgooglemaps-x-callback://?zoom=14&saddr= " + App.UserCurrentLatitude + "," + App.UserCurrentLongitude + "&daddr=" + item.xpos + "," + item.ypos + "&directionsmode=driving
</code>```

how can I show multiple points on map?

I tried adding this but didn't help.

```<code>waypoints=24.743449,46.658885/24.744560,46.660666
</code>```

anyone??

答:
After a lot of googling, I made it work like this:

```<code>comgooglemaps - x - callback://?zoom=14&saddr= " + App.UserCurrentLatitude + "," + App.UserCurrentLongitude + "&daddr=" + item.xpos + ",+" + item.ypos + "+to:24.123456,+24.234567&directionsmode=driving
</code>```

In case if anyone else is looking for the same.

Body:
I need to launch google maps with multiple waypoint showing on map on IOS using url in my Xamarin forms application.
I'm able to launch it with 2 points (Source and Destination) using this url:

comgooglemaps-x-callback://?zoom=14&saddr= " + App.UserCurrentLatitude + "," + App.UserCurrentLongitude + "&daddr=" + item.xpos + "," + item.ypos + "&directionsmode=driving

how can I show multiple points on map?

I tried adding this but didn't help.

waypoints=24.743449,46.658885/24.744560,46.660666

anyone??

Body:
After a lot of googling, I made it work like this:

comgooglemaps - x - callback://?zoom=14&saddr= " + App.UserCurrentLatitude + "," + App.UserCurrentLongitude + "&daddr=" + item.xpos + ",+" + item.ypos + "+to:24.123456,+24.234567&directionsmode=driving

In case if anyone else is looking for the same.


问:
XSL changing spaces in a link to %20
I  need to change links that are automatically created by MOSS07 with spaces to include %20.

Example:

```<code>{$SafeLinkURL}
</code>```

which would output https://stackoverflow.com/example of spaces

https://stackoverflow.com/example%20of%20spaces

If anyone can shed some light on this please do.

Thanks in advance,

Nick

答:
It isn't clear what exactly is asked for in this question.

In case the problem is to replace all space characters in a given string with "%20", here is an XSLT solution:

```<code><xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="link/text()[contains(., ' ')]">
  <xsl:call-template name="replace"/>
 </xsl:template>

 <xsl:template name="replace">
  <xsl:param name="pText" select="."/>
  <xsl:param name="pTarget" select="' '"/>
  <xsl:param name="pReplacement" select="'%20'"/>

  <xsl:choose>
   <xsl:when test="not(contains($pText, $pTarget))">
    <xsl:value-of select="$pText"/>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select=
      "substring-before($pText, $pTarget)"/>
     <xsl:value-of select="$pReplacement"/>
     <xsl:call-template name="replace">
       <xsl:with-param name="pText" select=
            "substring-after($pText, $pTarget)"/>
       <xsl:with-param name="pTarget" select="$pTarget"/>
       <xsl:with-param name="pReplacement"
            select="$pReplacement"/>
     </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>
</code>```

when this transformation is applied on this XML document:

```<code><link>http://stackoverflow.com/example of spaces</link>
</code>```

the wanted, correct result is produced:

```<code><link>http://stackoverflow.com/example%20of%20spaces</link>
</code>```

ContentLicense: CC BY-SA 2.5

Title: XSL changing spaces in a link to %20

Body:
I  need to change links that are automatically created by MOSS07 with spaces to include %20.

Example:

{$SafeLinkURL}

which would output https://stackoverflow.com/example of spaces

https://stackoverflow.com/example%20of%20spaces

If anyone can shed some light on this please do.

Thanks in advance,

Nick

Body:
It isn't clear what exactly is asked for in this question.

In case the problem is to replace all space characters in a given string with "%20", here is an XSLT solution:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="node()|@*">
  <xsl:copy>
   <xsl:apply-templates select="node()|@*"/>
  </xsl:copy>
 </xsl:template>

 <xsl:template match="link/text()[contains(., ' ')]">
  <xsl:call-template name="replace"/>
 </xsl:template>

 <xsl:template name="replace">
  <xsl:param name="pText" select="."/>
  <xsl:param name="pTarget" select="' '"/>
  <xsl:param name="pReplacement" select="'%20'"/>

  <xsl:choose>
   <xsl:when test="not(contains($pText, $pTarget))">
    <xsl:value-of select="$pText"/>
   </xsl:when>
   <xsl:otherwise>
     <xsl:value-of select=
      "substring-before($pText, $pTarget)"/>
     <xsl:value-of select="$pReplacement"/>
     <xsl:call-template name="replace">
       <xsl:with-param name="pText" select=
            "substring-after($pText, $pTarget)"/>
       <xsl:with-param name="pTarget" select="$pTarget"/>
       <xsl:with-param name="pReplacement"
            select="$pReplacement"/>
     </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>

when this transformation is applied on this XML document:

<link>http://stackoverflow.com/example of spaces</link>

the wanted, correct result is produced:

<link>http://stackoverflow.com/example%20of%20spaces</link>


问:
Get all text inside a tag in lxml
I'd like to write a code snippet that would grab all of the text inside the <content> tag, in lxml, in all three instances below, including the code tags. I've tried tostring(getchildren()) but that would miss the text in between the tags. I didn't have very much luck searching the API for a relevant function. Could you help me out?

<content>

Text inside tag

</content>
#should return "
Text inside tag

<content>
Text with no tag
</content>
#should return "Text with no tag"

<content>
Text outside tag
Text inside tag

</content>
#should return "Text outside tag
Text inside tag
"
```

答:
One of the simplest code snippets, that actually worked for me and as per documentation at http://lxml.de/tutorial.html#using-xpath-to-find-text is

```<code>etree.tostring(html, method="text")
</code>```

where etree is a node/tag whose complete text, you are trying to read. Behold that it doesn't get rid of script and style tags though.

ContentLicense: CC BY-SA 4.0

Title: Get all text inside a tag in lxml

Body:
One of the simplest code snippets, that actually worked for me and as per documentation at http://lxml.de/tutorial.html#using-xpath-to-find-text is

etree.tostring(html, method="text")

where etree is a node/tag whose complete text, you are trying to read. Behold that it doesn't get rid of script and style tags though.


问:
Maximum zoom level in iOS map using swift
I don't want the user to zoom out more. Is there a way to set max zoom level in Map kit using swift?

答:
How to limit zoomlevel:

```<code>class CustomMapOverlay: MKTileOverlay {

.
init() {
  self.minimumZ = 3
  self.maximumZ = 15
}
</code>```

}

or set min and maximumZ values in override func url(forTilePath path.
If other custom map overlays are used with higher maximumZ = 17 level at the same time then this 17 value will override our 15 level value.

Body:
How to limit zoomlevel:

class CustomMapOverlay: MKTileOverlay {

.
init() {
  self.minimumZ = 3
  self.maximumZ = 15
}

}

or set min and maximumZ values in override func url(forTilePath path.
If other custom map overlays are used with higher maximumZ = 17 level at the same time then this 17 value will override our 15 level value.


问:
SQL Select SQL Statement output + ( )
Table Name: aa_company

```<code>Column_A    Column_B    Column_C
ABC         0001        abc@gmail.com

BCD         0002        bcd@gmail.com

CDE         0003        cde@gmail.com

Select Column_A, Column_B, Column_C
FROM aa_company;
</code>```

if I want the output result add one more column, how can i do it?

```<code>Column_A    Column_B    Column_C          Column_D
ABC         0001        abc@gmail.com     ABC (0001)

BCD         0002        bcd@gmail.com     BCD (0002)

CDE         0003        cde@gmail.com     CDE (0003)
</code>```

答:
```<code>Select Column_A, Column_B, Column_C,Column_A + '('+Column_B+')'
FROM aa_company;
</code>```

Here the Column B seems to be numeric so you need to convert it into type varchar so the query would be like

```<code>Select Column_A, Column_B, Column_C,Column_A + '('+CONVERT(varchar(10),Column_B)+')'
FROM aa_company;
</code>```

to give header to the new column you can write as

```<code>Select Column_A, Column_B, Column_C,Column_A + '('+CONVERT(varchar(10),Column_B)+')' as Column_D
FROM aa_company;
</code>```

Title: SQL Select SQL Statement output + ( )

Body:
Table Name: aa_company

Column_A    Column_B    Column_C
ABC         0001        abc@gmail.com

BCD         0002        bcd@gmail.com

CDE         0003        cde@gmail.com

Select Column_A, Column_B, Column_C
FROM aa_company;

if I want the output result add one more column, how can i do it?

Column_A    Column_B    Column_C          Column_D
ABC         0001        abc@gmail.com     ABC (0001)

BCD         0002        bcd@gmail.com     BCD (0002)

CDE         0003        cde@gmail.com     CDE (0003)

Body:
Select Column_A, Column_B, Column_C,Column_A + '('+Column_B+')'
FROM aa_company;

Here the Column B seems to be numeric so you need to convert it into type varchar so the query would be like

Select Column_A, Column_B, Column_C,Column_A + '('+CONVERT(varchar(10),Column_B)+')'
FROM aa_company;

to give header to the new column you can write as

Select Column_A, Column_B, Column_C,Column_A + '('+CONVERT(varchar(10),Column_B)+')' as Column_D
FROM aa_company;


答:
First of all uncomment that

```<code>startActivityForResult(intent, MY_REQUEST_CODE_TWO);
</code>```

from onItemClick method of FirstActivity and comment

```<code>//startActivity(intent);
</code>```

Add this onActivityResult in FirstActivity

```<code>@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == MY_REQUEST_CODE_TWO) {
        Intent intent = new Intent();
        intent.putExtra("name", data.getExtras().getString("name"));
        intent.putExtra("id", data.getExtras().getString("id"));
        setResult(Activity.RESULT_OK, intent);
        finish();
    }
}
</code>```

Explanation:

The result of SecondActivity will be delivered to FirstActivity and the result of FirstActivity will be delivered to the FragmentActivity

Title: how i can get onActivityResult in fragment from secondActivity

Body:
First of all uncomment that

startActivityForResult(intent, MY_REQUEST_CODE_TWO);

from onItemClick method of FirstActivity and comment

//startActivity(intent);

Add this onActivityResult in FirstActivity

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == MY_REQUEST_CODE_TWO) {
        Intent intent = new Intent();
        intent.putExtra("name", data.getExtras().getString("name"));
        intent.putExtra("id", data.getExtras().getString("id"));
        setResult(Activity.RESULT_OK, intent);
        finish();
    }
}

Explanation:

The result of SecondActivity will be delivered to FirstActivity and the result of FirstActivity will be delivered to the FragmentActivity


问:
"Module name is invalid" when exporting an existing eclipse project to a war file
I am trying to export an existing Eclipse project to a war file. But whatever I typed in the "WAR Export" dialog page, the system always returned "Module name is invalid". I do not know how to fix this issue. Thanks for the help.</p>

答:
In Eclipse STS

Right-click on folder project.

Click on properties.

Go to project facets.

Choose your Java 1.8

Scroll down to Configuration and mark Dynamic Web Module.

After that, it works fine.


问:
Casperjs Google Login (V2) Not working
I´m using casperjs (so phantomjs in the middle) to access some google utilities but, before accessing them we should be logged in google. For V1 google authentication, we are using the following script:

```<code>var casper = require('casper').create();
url = 'https://accounts.google.com/ServiceLogin?passive=1209600&continue=https%3A%2F%2Faccounts.google.com%2FManageAccount&followup=https%3A%2F%2Faccounts.google.com%2FManageAccount&flowName=GlifWebSignIn&flowEntry=ServiceLogin&nojavascript=1#identifier';
casper.start(url, function() {

  this.fillSelectors('form#gaia_loginform', {
    'input[name="Email"]': 'your@email',
  }); //Fills the email box with email
  this.click("#next");

  this.wait(500, function() { //Wait for next page to load
    this.waitForSelector("#Passwd", //Wait for password box
      function success() {
        console.log("SUCCESS...");
        this.fillSelectors('form#gaia_loginform', {
          'input[name="Passwd"]': 'yourPassw',
        }); //Fill password box with PASSWORD
        this.click("#signIn"); //Click sign in button
        this.wait(500, function() {}); //Wait for it fully sigin
        casper.thenOpen('http://utility.google.com/', function() {
            this.wait(2000, function() {
                this.capture('media/status.png', undefined, {
                    format: 'png',
                    quality: 100`enter code here`
                });
            });
        });
      },
      function fail() {
        console.log("FAIL...");
      }
    );
  });
});
casper.run();
</code>```

We have changed the way that we manipulate the form and fill the fields and It's working so far. The problem with V2 authentication is that triggering the mouse events isn't possible, that means we can't click using this.click("#next") and this.click("#signIn"). I tried doing post over the form, using different mouse events and also trying to manipulate directly the jsaction events. Nothing works.

Someone has an idea on how to solve this issue? Thank you so much!

答:
I also trying same and I found that the click is working with this.click('#identifierNext'); and Google loaders start working. if you use following code after click to take screenshots you can see loader comes up but after that instead of going to Password screen it comes back to email screen.

Screenshot code

```<code>this.wait(200, function(){
    this.capture('1.jpg',{
        top: 0,
        left: 0,
        width: 4608,
        height: 3456,
        quality:20
    });
});
this.wait(100, function(){
    this.capture('2.jpg',{
        top: 0,
        left: 0,
        width: 4608,
        height: 3456,
        quality:20
    });
});
this.wait(100, function(){
    this.capture('3.jpg',{
        top: 0,
        left: 0,
        width: 4608,
        height: 3456,
        quality:20
    });
});
this.wait(100, function(){
    this.capture('4.jpg',{
        top: 0,
        left: 0,
        width: 4608,
        height: 3456,
        quality:20
    });
});
</code>```

But I am also not able to reach Password screen, if with this help you can come with any idea let me know.

Title: Casperjs Google Login (V2) Not working

Body:
I´m using casperjs (so phantomjs in the middle) to access some google utilities but, before accessing them we should be logged in google. For V1 google authentication, we are using the following script:

var casper = require('casper').create();
url = 'https://accounts.google.com/ServiceLogin?passive=1209600&continue=https%3A%2F%2Faccounts.google.com%2FManageAccount&followup=https%3A%2F%2Faccounts.google.com%2FManageAccount&flowName=GlifWebSignIn&flowEntry=ServiceLogin&nojavascript=1#identifier';
casper.start(url, function() {

  this.fillSelectors('form#gaia_loginform', {
    'input[name="Email"]': 'your@email',
  }); //Fills the email box with email
  this.click("#next");

  this.wait(500, function() { //Wait for next page to load
    this.waitForSelector("#Passwd", //Wait for password box
      function success() {
        console.log("SUCCESS...");
        this.fillSelectors('form#gaia_loginform', {
          'input[name="Passwd"]': 'yourPassw',
        }); //Fill password box with PASSWORD
        this.click("#signIn"); //Click sign in button
        this.wait(500, function() {}); //Wait for it fully sigin
        casper.thenOpen('http://utility.google.com/', function() {
            this.wait(2000, function() {
                this.capture('media/status.png', undefined, {
                    format: 'png',
                    quality: 100`enter code here`
                });
            });
        });
      },
      function fail() {
        console.log("FAIL...");
      }
    );
  });
});
casper.run();

We have changed the way that we manipulate the form and fill the fields and It's working so far. The problem with V2 authentication is that triggering the mouse events isn't possible, that means we can't click using this.click("#next") and this.click("#signIn"). I tried doing post over the form, using different mouse events and also trying to manipulate directly the jsaction events. Nothing works.

Someone has an idea on how to solve this issue? Thank you so much!

Body:
I also trying same and I found that the click is working with this.click('#identifierNext'); and Google loaders start working. if you use following code after click to take screenshots you can see loader comes up but after that instead of going to Password screen it comes back to email screen.

Screenshot code

this.wait(200, function(){
    this.capture('1.jpg',{
        top: 0,
        left: 0,
        width: 4608,
        height: 3456,
        quality:20
    });
});
this.wait(100, function(){
    this.capture('2.jpg',{
        top: 0,
        left: 0,
        width: 4608,
        height: 3456,
        quality:20
    });
});
this.wait(100, function(){
    this.capture('3.jpg',{
        top: 0,
        left: 0,
        width: 4608,
        height: 3456,
        quality:20
    });
});
this.wait(100, function(){
    this.capture('4.jpg',{
        top: 0,
        left: 0,
        width: 4608,
        height: 3456,
        quality:20
    });
});

But I am also not able to reach Password screen, if with this help you can come with any idea let me know.


问:
CSS 3 : Image doesn't get 100% of div
I have a div in which I am displaying an image. The image is bigger than its contained div.

somehow I get space to top and bottom of the image.

.image_contain_div {
  height: 130px;
  padding: 5px;
  width: 180px;
  border: thin black solid;
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}
.image_contain_div .image_div {
  background: #000;
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
  height: 100%;
  width: 100%;
  position: relative;
}
.image_contain_div .image_div .custom_website_default_image_div {
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}
.image_contain_div .image_div .custom_website_default_image_div svg {
  width: 26px;
  height: 26px;
}
.image_contain_div .image_div img {
  max-width: 100%;
  max-height: 100%;
}
.image_contain_div .image_div .custom_website_image_overlay_div {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
}
.image_contain_div .image_div .custom_website_image_overlay_div svg {
  width: 30px;
  height: 30px;
}
.image_contain_div .image_div:hover .custom_website_image_overlay_div {
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="image_contain_div b">
    <div class="image_div ">

        <img src="https://d28hsb6vkzynsw.cloudfront.net/banner/2877/500/99041_banner_testfile.jpeg" alt="">

        <div class="custom_website_image_overlay_div">
            <span class="cursor_pointer">
                <svg  class="v-middle" style="enable-background:new 0 0 33.004 33.004;" viewBox="0 0 33.004 33.004"  x="0px" xmlns="http://www.w3.org/2000/svg" y="0px">
                    <path  d="M33.004,15.414H17.59V0h-2.176v15.414H0v2.176h15.414v15.414h2.176V17.59h15.414V15.414z" style="fill:#fff;"></path>
                </svg>
            </span>
        </div>

    </div>
</div></code>```

I want to cover the image to the black background div.

Note : If image is smaller than the div then it should be in the middle of the div.

Any help would be great.

Thank You.

答:
If you don't mind using the style attribute you could set the image as background-image and the background-size to cover like so:

 .image_div {
   background: no-repeat center;
   background-size: cover;
 }```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="image_contain_div b">
  <div class="image_div" style="background-image: url('https://d28hsb6vkzynsw.cloudfront.net/banner/2877/500/99041_banner_testfile.jpeg')">

    <div class="custom_website_image_overlay_div">
      <span class="cursor_pointer">
                    <svg  class="v-middle" style="enable-background:new 0 0 33.004 33.004;" viewBox="0 0 33.004 33.004"  x="0px" xmlns="http://www.w3.org/2000/svg" y="0px">
                        <path  d="M33.004,15.414H17.59V0h-2.176v15.414H0v2.176h15.414v15.414h2.176V17.59h15.414V15.414z" style="fill:#fff;"></path>
                    </svg>
                </span>
    </div>

  </div>
</div></code>```

Title: CSS 3 : Image doesn't get 100% of div

Body:
I have a div in which I am displaying an image. The image is bigger than its contained div.

somehow I get space to top and bottom of the image.

.image_contain_div {
  height: 130px;
  padding: 5px;
  width: 180px;
  border: thin black solid;
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}
.image_contain_div .image_div {
  background: #000;
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
  height: 100%;
  width: 100%;
  position: relative;
}
.image_contain_div .image_div .custom_website_default_image_div {
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}
.image_contain_div .image_div .custom_website_default_image_div svg {
  width: 26px;
  height: 26px;
}
.image_contain_div .image_div img {
  max-width: 100%;
  max-height: 100%;
}
.image_contain_div .image_div .custom_website_image_overlay_div {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
}
.image_contain_div .image_div .custom_website_image_overlay_div svg {
  width: 30px;
  height: 30px;
}
.image_contain_div .image_div:hover .custom_website_image_overlay_div {
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}

                <svg  class="v-middle" style="enable-background:new 0 0 33.004 33.004;" viewBox="0 0 33.004 33.004"  x="0px" xmlns="http://www.w3.org/2000/svg" y="0px">
                    <path  d="M33.004,15.414H17.59V0h-2.176v15.414H0v2.176h15.414v15.414h2.176V17.59h15.414V15.414z" style="fill:#fff;"></path>
                </svg>

I want to cover the image to the black background div.

Note : If image is smaller than the div then it should be in the middle of the div.

Any help would be great.

Thank You.

Body:
If you don't mind using the style attribute you could set the image as background-image and the background-size to cover like so:

 .image_div {
   background: no-repeat center;
   background-size: cover;
 }

<div class="image_contain_div b">
  <div class="image_div" style="background-image: url('https://d28hsb6vkzynsw.cloudfront.net/banner/2877/500/99041_banner_testfile.jpeg')">

    <div class="custom_website_image_overlay_div">
      <span class="cursor_pointer">
                    <svg  class="v-middle" style="enable-background:new 0 0 33.004 33.004;" viewBox="0 0 33.004 33.004"  x="0px" xmlns="http://www.w3.org/2000/svg" y="0px">
                        <path  d="M33.004,15.414H17.59V0h-2.176v15.414H0v2.176h15.414v15.414h2.176V17.59h15.414V15.414z" style="fill:#fff;"></path>
                    </svg>
                </span>
    </div>

  </div>
</div>


问:
NFC implemetation in iOS7
I am planning to implement NFC in iPhone. I would like to know that iOS7 can use NFC sdk.
When I research about NFC, I found that is the new sdk for iOS 11 and heigher. I just found out some examples for NFC but they are implemented using swift. I also would like to know that I can also use objective c to implement NFC.</p>

答:
You can use CoreNFC from Objective-C on iOS 11.

Be aware that it is only supported iPhone 7 and 7plus (presumably it will also be supported on any new phones that are released).

You cannot use it in iOS 7

Title: NFC implemetation in iOS7


问:
How do I get content from push notification?
Using Swift3 with xcode8.3

Below is my function code

```<code>func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    print("==== didReceiveRemoteNotification ====")
    print(userInfo)

    let state = UIApplication.shared.applicationState

    if state == .background {
        // background
        if let pushUrl = userInfo[AnyHashable("url")] as? String {
            viewController?.redirectTo(url: pushUrl)
        }
    }
    else if state == .active {
        // foreground
        print("==== foreground Running ====")
        let pushUrl = userInfo[AnyHashable("url")]
        let pushApns = userInfo[AnyHashable("aps")]
        let pushAlert = pushApns["alert"]
        viewController?.showAlertBox(url: pushUrl as! String, msg: pushAlert)
    }
}
</code>```

When I receive a notification on foreground, I need to get the content from it and pass it to viewController.

below is the log from my Xcode

```<code>==== didReceiveRemoteNotification ====
[AnyHashable("aps"): {
    alert = "this is alert";
    badge = 0;
}, AnyHashable("url"): https://www.google.com]
</code>```

But the code above is not working? How can I get "alert" and "url" content from notification?

答:
To access alert try  using</p>

```<code>if let aps = userInfo["aps"] as? [String:AnyObject] {
     if let alert = aps["alert"] as? NSString {
      //Use alert
    }
    if let alert = aps["badge"] as? NSNumber {
      //Use badge
    }
}
  if let url = userInfo["url"] as? String {
 // use url
}
</code>```

Body:
Using Swift3 with xcode8.3

Below is my function code

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    print("==== didReceiveRemoteNotification ====")
    print(userInfo)

    let state = UIApplication.shared.applicationState

    if state == .background {
        // background
        if let pushUrl = userInfo[AnyHashable("url")] as? String {
            viewController?.redirectTo(url: pushUrl)
        }
    }
    else if state == .active {
        // foreground
        print("==== foreground Running ====")
        let pushUrl = userInfo[AnyHashable("url")]
        let pushApns = userInfo[AnyHashable("aps")]
        let pushAlert = pushApns["alert"]
        viewController?.showAlertBox(url: pushUrl as! String, msg: pushAlert)
    }
}

When I receive a notification on foreground, I need to get the content from it and pass it to viewController.

below is the log from my Xcode

==== didReceiveRemoteNotification ====
[AnyHashable("aps"): {
    alert = "this is alert";
    badge = 0;
}, AnyHashable("url"): https://www.google.com]

But the code above is not working? How can I get "alert" and "url" content from notification?

Body:
To access alert try  using

if let aps = userInfo["aps"] as? [String:AnyObject] {
     if let alert = aps["alert"] as? NSString {
      //Use alert
    }
    if let alert = aps["badge"] as? NSNumber {
      //Use badge
    }
}
  if let url = userInfo["url"] as? String {
 // use url
}


问:
MS Access 200X Image export with PHP?
i'm using mdbtools to get data from MS Access to sqlite... using PHP but now i want to get an image.</p>

答:
I finally answered my own question. All the details are posted here:

https://beeznest.wordpress.com/2010/12/16/leer-imagen-desde-un-campo-ole-object-de-access-con-php/

(spanish)

Title: MS Access 200X Image export with PHP?


问:
Condition inside a Where clause in sql
I have a stored procedure. In that where condition, I want to select the not null value if there are any, else select the null value from the table. Anyone Kindly help me.. </p>

```<code>ALTER PROCEDURE SearchPromotionBYPromotionANDVehicleID

@PromotionCode VARCHAR(100)
,@TypeId INT
,@LocationId INT
,@ClientId INT
AS
BEGIN

SET NOCOUNT ON;

SELECT top 1 tp.PromotionID
    ,tp.PromotionCode
    ,tp.ClientID
    ,tp.StartDate
    ,tp.EndDate
    ,tp.VehicleTypeId
    ,tv.VehicleType
    ,tp.LocationId

FROM tblstudent tp
LEFT OUTER JOIN tblType tv ON tp.TypeId = tv.TypeId
WHERE tp.PromotionCode = @PromotionCode

    AND
     ( ( @LocationId IS NOT NULL AND tp.LocationId = @LocationId ) OR (tp.LocationId IS NULL) OR (@LocationId IS NULL) or (tp.LocationId = 0 ) )
</code>```

<p>In this consider 2 records (r1 and r2) with same promotion code and one with all locations (that is location id 0) and another with a location ID. When the parameter @locationId have a value(consider the value equal to the value of the record r2) then it have to return the record 2. Else have to return r1. </p>

答:
```<code>WHERE tp.PromotionCode = @PromotionCode
AND (( @LocationId IS NOT NULL AND tp.LocationId = @LocationId ) OR tp.LocationId IS NULL)
</code>```

This condition selects those values where @LocationId has a not null and not 0 value, And the value needs to match with tp.LocationId, Otherwise it returns those where tp.LocationId is null.
Is it the result what you want? If you want different, let me know

Title: Condition inside a Where clause in sql

Body:
I have a stored procedure. In that where condition, I want to select the not null value if there are any, else select the null value from the table. Anyone Kindly help me..

ALTER PROCEDURE SearchPromotionBYPromotionANDVehicleID

@PromotionCode VARCHAR(100)
,@TypeId INT
,@LocationId INT
,@ClientId INT
AS
BEGIN

SET NOCOUNT ON;

SELECT top 1 tp.PromotionID
    ,tp.PromotionCode
    ,tp.ClientID
    ,tp.StartDate
    ,tp.EndDate
    ,tp.VehicleTypeId
    ,tv.VehicleType
    ,tp.LocationId

FROM tblstudent tp
LEFT OUTER JOIN tblType tv ON tp.TypeId = tv.TypeId
WHERE tp.PromotionCode = @PromotionCode

    AND
     ( ( @LocationId IS NOT NULL AND tp.LocationId = @LocationId ) OR (tp.LocationId IS NULL) OR (@LocationId IS NULL) or (tp.LocationId = 0 ) )

In this consider 2 records (r1 and r2) with same promotion code and one with all locations (that is location id 0) and another with a location ID. When the parameter @locationId have a value(consider the value equal to the value of the record r2) then it have to return the record 2. Else have to return r1.

Body:
WHERE tp.PromotionCode = @PromotionCode
AND (( @LocationId IS NOT NULL AND tp.LocationId = @LocationId ) OR tp.LocationId IS NULL)

This condition selects those values where @LocationId has a not null and not 0 value, And the value needs to match with tp.LocationId, Otherwise it returns those where tp.LocationId is null.
Is it the result what you want? If you want different, let me know


问:
Prevent commit of files with same names
Assuming there's a Git repository hosted on a Linux machine and there are developers using both Windows and Linux, is there a way to prevent Linux developers from committing files with same names but different cases?

I think I've to write a server-side hook for this, but I don't know how to validate the names of incoming files inside the hook script.

Any help/references related to this would be appreciated.

答: If you want keep some files locally then git stash is your friend. stash usage

Title: Prevent commit of files with same names


答:
Add this:

```<code>.image_div img {
  object-fit: cover;
  min-height: 100%;
}
</code>```

in your CSS like so:

.image_contain_div {
  height: 130px;
  padding: 5px;
  width: 180px;
  border: thin black solid;
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}
.image_contain_div .image_div {
  background: #000;
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
  height: 100%;
  width: 100%;
  position: relative;
}
.image_contain_div .image_div .custom_website_default_image_div {
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}
.image_contain_div .image_div .custom_website_default_image_div svg {
  width: 26px;
  height: 26px;
}
.image_contain_div .image_div img {
  max-width: 100%;
  max-height: 100%;
}
.image_contain_div .image_div .custom_website_image_overlay_div {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
}
.image_contain_div .image_div .custom_website_image_overlay_div svg {
  width: 30px;
  height: 30px;
}
.image_contain_div .image_div:hover .custom_website_image_overlay_div {
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}

.image_div img {
  object-fit: cover;
  min-height: 100%;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="image_contain_div b">
                                        <div class="image_div ">

                                          <img src="https://d28hsb6vkzynsw.cloudfront.net/banner/2877/500/99041_banner_testfile.jpeg" alt="">

                                          <div class="custom_website_image_overlay_div">
                                            <span class="cursor_pointer">
                                              <svg  class="v-middle" style="enable-background:new 0 0 33.004 33.004;" viewBox="0 0 33.004 33.004"  x="0px" xmlns="http://www.w3.org/2000/svg" y="0px">
                                                <path  d="M33.004,15.414H17.59V0h-2.176v15.414H0v2.176h15.414v15.414h2.176V17.59h15.414V15.414z" style="fill:#fff;"></path>
                                              </svg>
                                            </span>

                                          </div>

                                        </div>
                                      </div></code>```

Title: CSS 3 : Image doesn't get 100% of div

Body:
Add this:

.image_div img {
  object-fit: cover;
  min-height: 100%;
}

in your CSS like so:

.image_contain_div {
  height: 130px;
  padding: 5px;
  width: 180px;
  border: thin black solid;
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}
.image_contain_div .image_div {
  background: #000;
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
  height: 100%;
  width: 100%;
  position: relative;
}
.image_contain_div .image_div .custom_website_default_image_div {
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}
.image_contain_div .image_div .custom_website_default_image_div svg {
  width: 26px;
  height: 26px;
}
.image_contain_div .image_div img {
  max-width: 100%;
  max-height: 100%;
}
.image_contain_div .image_div .custom_website_image_overlay_div {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
}
.image_contain_div .image_div .custom_website_image_overlay_div svg {
  width: 30px;
  height: 30px;
}
.image_contain_div .image_div:hover .custom_website_image_overlay_div {
  /* Firefox */
  display: -moz-box;
  -moz-box-orient: horizontal;
  -moz-box-pack: center;
  -moz-box-align: center;
  /* Safari and Chrome */
  display: -webkit-box;
  -webkit-box-orient: horizontal;
  -webkit-box-pack: center;
  -webkit-box-align: center;
  /* W3C */
  display: box;
  box-orient: horizontal;
  box-pack: center;
  box-align: center;
  /* IE10 -Doesn't work yet! */
  display: -ms-flexbox;
  -ms-flex-align: center;
  -ms-flex-pack: center;
  -ms-box-orient: horizontal;
}

.image_div img {
  object-fit: cover;
  min-height: 100%;
}

<div class="image_contain_div b">
                                        <div class="image_div ">

                                          <img src="https://d28hsb6vkzynsw.cloudfront.net/banner/2877/500/99041_banner_testfile.jpeg" alt="">

                                          <div class="custom_website_image_overlay_div">
                                            <span class="cursor_pointer">
                                              <svg  class="v-middle" style="enable-background:new 0 0 33.004 33.004;" viewBox="0 0 33.004 33.004"  x="0px" xmlns="http://www.w3.org/2000/svg" y="0px">
                                                <path  d="M33.004,15.414H17.59V0h-2.176v15.414H0v2.176h15.414v15.414h2.176V17.59h15.414V15.414z" style="fill:#fff;"></path>
                                              </svg>
                                            </span>

                                          </div>

                                        </div>
                                      </div>


问:
evaluating else if after an if condition is true
Consider this snippet:

```<code>private void button1_Click(object sender, EventArgs e)
{
    if (textBox1.MaxLength > 0)
    {
        textBox2.Text = Convert.ToBoolean(Math.Sqrt(textBox1.MaxLength)).ToString();
    }
    else if (textBox1.MaxLength < 32768)
    {
        textBox2.Text = Convert.ToBoolean(Math.Sqrt(textBox1.MaxLength)).ToString();
    }
}
</code>```

Why is it not evaluating the second condition (the lesser than condition)? It's also true, isn't it?

If I have to make the second one to work in the same condition, what minor change must be made?

答:
I would do this, if I would like to say "if MaxLength is between 0 and 32768":

```<code>if (0 < textBox1.MaxLength && textBox1.MaxLength < 32768)
    textBox2.Text = Convert.ToBoolean(Math.Sqrt(textBox1.MaxLength)).ToString();
</code>```

Since you're doing the same in this interval, it is more appropriate to make both in the same condition statement.

Body:
Consider this snippet:

private void button1_Click(object sender, EventArgs e)
{
    if (textBox1.MaxLength > 0)
    {
        textBox2.Text = Convert.ToBoolean(Math.Sqrt(textBox1.MaxLength)).ToString();
    }
    else if (textBox1.MaxLength < 32768)
    {
        textBox2.Text = Convert.ToBoolean(Math.Sqrt(textBox1.MaxLength)).ToString();
    }
}

Why is it not evaluating the second condition (the lesser than condition)? It's also true, isn't it?

If I have to make the second one to work in the same condition, what minor change must be made?

Body:
I would do this, if I would like to say "if MaxLength is between 0 and 32768":

if (0 < textBox1.MaxLength && textBox1.MaxLength < 32768)
    textBox2.Text = Convert.ToBoolean(Math.Sqrt(textBox1.MaxLength)).ToString();

Since you're doing the same in this interval, it is more appropriate to make both in the same condition statement.


问:
How to sudo run a local script over ssh
I try to sudo run a local script over ssh,

```<code>ssh $HOST < script.sh
</code>```

and I tried

```<code>ssh -t $HOST "sudo -s && bash" < script.sh
</code>```

Actually, I searched a lot in google, find some similar questions, however, I don't find a solution which can sudo run a local script.

答:
Reading the error message of

```<code>$ ssh -t $HOST "sudo -s && bash" < script.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.
</code>```

makes it pretty clear what's going wrong here.

You can't use the ssh parameter -t (which sudo needs to ask for a password) whilst redirecting your script to bash's stdin of your remote session.

If it is acceptable for you, you could transfer the local script via scp to your remote machine and then execute the script without the need of I/O redirection:

```<code>scp script.sh $HOST:/tmp/ && ssh -t $HOST "sudo -s bash /tmp/script.sh"
</code>```

Another way to fix your issue is to use sudo in non-interactive mode -n but for this you need to set NOPASSWD within the remote machine's sudoers file for the executing user. Then you can use

```<code>ssh $HOST "sudo -n -s bash" < script.sh
</code>```

Title: How to sudo run a local script over ssh

Body:
I try to sudo run a local script over ssh,

ssh $HOST < script.sh

and I tried

ssh -t $HOST "sudo -s && bash" < script.sh

Actually, I searched a lot in google, find some similar questions, however, I don't find a solution which can sudo run a local script.

Body:
Reading the error message of

$ ssh -t $HOST "sudo -s && bash" < script.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.

makes it pretty clear what's going wrong here.

You can't use the ssh parameter -t (which sudo needs to ask for a password) whilst redirecting your script to bash's stdin of your remote session.

If it is acceptable for you, you could transfer the local script via scp to your remote machine and then execute the script without the need of I/O redirection:

scp script.sh $HOST:/tmp/ && ssh -t $HOST "sudo -s bash /tmp/script.sh"

Another way to fix your issue is to use sudo in non-interactive mode -n but for this you need to set NOPASSWD within the remote machine's sudoers file for the executing user. Then you can use

ssh $HOST "sudo -n -s bash" < script.sh


问:
Not showing the Modal
I want to show a notification modal when i submit a form.but unfortunately the modal is not popping up here is the code

$("#submitmodalRetailer").submit(function() {
  var FirstName = $('#FirstNameRetailer').val();
  var LastName = $('#LastNameRetailer').val();
  var QRCodeRetailer = $('#QRCodeRetailer').val();
  var prefixNumberRetailers = $('#prefixNumberRetailer').val();
  var Retailer7Digits = $('#Retailer7Digit').val();
  $.ajax({
    type: "POST",
    url: "addRetailer.php",
    data: $('form.form-modal-retailer').serialize(),
    success: function(msg) {
      $("#RetailerAdd").modal('hide');
      location.reload();
      if (msg == 'Valid') {
        $("#RetailerAddshow").modal('show');
      } else if (msg == 'AlreadyExists') {
        $("#BarcodeExists").modal();
      } else if (msg == 'Invalid') {
        alert('Your Barcode number is invalid. \n User only 100001 to 199999')
      }
    },
    error: function() {
      alert("failure");
    }
  });
  return false;
});```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script></code>```

答:
You need to prevent the default action of the submit button.
Use preventDefault().

Read about it here: https://api.jquery.com/event.preventdefault/

```<code> $("#submitmodalRetailer").submit(function (e) {
     e.preventDefault();
 });
</code>```

Title: Not showing the Modal

Body:
You need to prevent the default action of the submit button.
Use preventDefault().

Read about it here: https://api.jquery.com/event.preventdefault/

 $("#submitmodalRetailer").submit(function (e) {
     e.preventDefault();
 });


问:
ACE Editor Autocomplete tooltip
I'm actually trying to use the ACE Editor Autocomplete function.
I have added custom functions (and objects) to my script and I want to display them in my autocompletion.
I could display use the "caption", "value" and "meta" property. But I did not very well understand how the "score" work precisely.

And (the objective of this post) I would like to know how to display a tooltip (like the ones pre-registred).

For your information, I am using Lua mode and I need custom autocomplete, because I am using proxy objects for Moonsharp.

Thank's and best regards.

答: add getDocTooltip method to your completer similar to https://github.com/ajaxorg/ace/blob/v1.2.8/lib/ace/ext/language_tools.js#L73</p>

Title: ACE Editor Autocomplete tooltip


问:
SetInterval function is playing audio twice instead of once
I am running into a wierd issue , I am building a simon says game for freecodecamp, but everytime I run the function below it is playing the audio twice . even though I am only calling the function once , any ideas?</p>

```<code>change('#8B0000','#E8A5A5','1000','1000','#2');
  var redSound = new
   Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
   var blueSound = new
 Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
 var greenSound = new Audio
("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
 var yellowSound = new Audio
 ("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");

function change(color1, color2,c1,c2,button){
    console.log("Inside Start of function");
var timer = setInterval(function first_color() {
  $(button).css('background',color2);
 if(color2 == '#34d955'){
    greenSound.play()
    } else if(color2 == '#E8A5A5'){
    redSound.play()
    } else if(color2 =='#F3FEA5'){
        yellowSound.play();
    }else if(color2 == '#A5DEFE'){
        blueSound.play()
    }

   setTimeout(change_color, c2);
 }, c1);//
 function change_color() {
    $(button).css('background',color1);
     clearInterval(timer);
   }
</code>```

答:
Odds are your timer is being fired twice before your timeout is being called.

Inside of your interval keep track of which sound is playing and return if you already called the method to play the sound.

```<code>var playing = null;
function change(color1, color2, c1, c2, button) {
    console.log("Inside Start of function");
    var timer = setInterval(function first_color() {
        if (playing == color2) return;
        playing = color2;
        $(button).css('background', color2);
        if (color2 == '#34d955') {
                greenSound.play()
        } else if (color2 == '#E8A5A5') {
            redSound.play()
        } else if (color2 == '#F3FEA5') {
            yellowSound.play();
        } else if (color2 == '#A5DEFE') {
            blueSound.play()
        }

        setTimeout(change_color, c2);
    }, c1);//
    function change_color() {
        $(button).css('background', color1);
        clearInterval(timer);
    }
</code>```

Body:
I am running into a wierd issue , I am building a simon says game for freecodecamp, but everytime I run the function below it is playing the audio twice . even though I am only calling the function once , any ideas?

change('#8B0000','#E8A5A5','1000','1000','#2');
  var redSound = new
   Audio("https://s3.amazonaws.com/freecodecamp/simonSound1.mp3");
   var blueSound = new
 Audio("https://s3.amazonaws.com/freecodecamp/simonSound2.mp3");
 var greenSound = new Audio
("https://s3.amazonaws.com/freecodecamp/simonSound3.mp3");
 var yellowSound = new Audio
 ("https://s3.amazonaws.com/freecodecamp/simonSound4.mp3");

function change(color1, color2,c1,c2,button){
    console.log("Inside Start of function");
var timer = setInterval(function first_color() {
  $(button).css('background',color2);
 if(color2 == '#34d955'){
    greenSound.play()
    } else if(color2 == '#E8A5A5'){
    redSound.play()
    } else if(color2 =='#F3FEA5'){
        yellowSound.play();
    }else if(color2 == '#A5DEFE'){
        blueSound.play()
    }

   setTimeout(change_color, c2);
 }, c1);//
 function change_color() {
    $(button).css('background',color1);
     clearInterval(timer);
   }

Body:
Odds are your timer is being fired twice before your timeout is being called.

Inside of your interval keep track of which sound is playing and return if you already called the method to play the sound.

var playing = null;
function change(color1, color2, c1, c2, button) {
    console.log("Inside Start of function");
    var timer = setInterval(function first_color() {
        if (playing == color2) return;
        playing = color2;
        $(button).css('background', color2);
        if (color2 == '#34d955') {
                greenSound.play()
        } else if (color2 == '#E8A5A5') {
            redSound.play()
        } else if (color2 == '#F3FEA5') {
            yellowSound.play();
        } else if (color2 == '#A5DEFE') {
            blueSound.play()
        }

        setTimeout(change_color, c2);
    }, c1);//
    function change_color() {
        $(button).css('background', color1);
        clearInterval(timer);
    }


问:
Return Ajax data on Index() in MVC 5
I have Index() which return empty view() like below

```<code>public ActionResult Index()
    {
        return View();
    }
</code>```

And GetDashboardSummaryData() which accept int parameter.

```<code>[HttpPost]
public ContentResult GetDashboardSummaryData(int year)
{
  ContentResult json = new ContentResult();
  json.Content = JsonConvert.SerializeObject(dashboardSummaryListViewModels);
  json.ContentType = "application/json";
  json.ContentEncoding = Encoding.UTF8;
  return json;

}
</code>```

On my cshtml page

```<code> $(document).ready(function () {
    year = new Date().getFullYear();
    GetDashboardSummaryData(year);
 });

function GetDashboardSummaryData(year) {
    var url = "@Url.Content("~/Dashboard/GetDashboardSummaryData")";
    url = url + "?year=" + year;
    $.ajax
      ({
          type: "POST",
          url: url,
          success: function (data) {
            //Populating chart data using data
        });

}
</code>```

Above all functionality is working as expected but when I debug my code first it goes to the Index() which basically return empty view and on document.ready event it again does AJAX call to fetch data from server side.

Is it possible that retrieve data for the current year on page load event(i.e. in Index()) itself instead of another separate ajax call to get initial data.

答:
You can use @Url.Action() in your javascript code then use JsonResult return type with controller action like following.

//javascript

```<code>$(document).ready(function () {
    year = new Date().getFullYear();
    GetDashboardSummaryData(year);
});

function GetDashboardSummaryData(year) {
    var url = '@Url.Action("GetDashboardSummaryData","Dashboard")';
    url = url + "/" + year;
    $.ajax
      ({
          type: "POST",
          url: url,
          success: function (data) {
            console.log(data)
        });

}
</code>```

//controller

```<code>[HttpPost]
public JsonResult GetDashboardSummaryData(int? year)
{
  var result = JsonConvert.SerializeObject(dashboardSummaryListViewModels);
  val year = year;
  return return Json(new {model = result , year = year});

}
</code>```

Title: Return Ajax data on Index() in MVC 5

Body:
I have Index() which return empty view() like below

public ActionResult Index()
    {
        return View();
    }

And GetDashboardSummaryData() which accept int parameter.

[HttpPost]
public ContentResult GetDashboardSummaryData(int year)
{
  ContentResult json = new ContentResult();
  json.Content = JsonConvert.SerializeObject(dashboardSummaryListViewModels);
  json.ContentType = "application/json";
  json.ContentEncoding = Encoding.UTF8;
  return json;

}

On my cshtml page

 $(document).ready(function () {
    year = new Date().getFullYear();
    GetDashboardSummaryData(year);
 });

function GetDashboardSummaryData(year) {
    var url = "@Url.Content("~/Dashboard/GetDashboardSummaryData")";
    url = url + "?year=" + year;
    $.ajax
      ({
          type: "POST",
          url: url,
          success: function (data) {
            //Populating chart data using data
        });

}

Above all functionality is working as expected but when I debug my code first it goes to the Index() which basically return empty view and on document.ready event it again does AJAX call to fetch data from server side.

Is it possible that retrieve data for the current year on page load event(i.e. in Index()) itself instead of another separate ajax call to get initial data.

Body:
You can use @Url.Action() in your javascript code then use JsonResult return type with controller action like following.

//javascript

$(document).ready(function () {
    year = new Date().getFullYear();
    GetDashboardSummaryData(year);
});

function GetDashboardSummaryData(year) {
    var url = '@Url.Action("GetDashboardSummaryData","Dashboard")';
    url = url + "/" + year;
    $.ajax
      ({
          type: "POST",
          url: url,
          success: function (data) {
            console.log(data)
        });

}

//controller

[HttpPost]
public JsonResult GetDashboardSummaryData(int? year)
{
  var result = JsonConvert.SerializeObject(dashboardSummaryListViewModels);
  val year = year;
  return return Json(new {model = result , year = year});

}