@WebListener
public class MyApplicationLifeCicleListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) {
// cохраняем куда-нибудь путь
System.out.println(event.getServletContext().getContextPath());
}
@Override
public void contextDestroyed(ServletContextEvent event) {
}
}
@WebListener
public class MyRequestListener extends RequestContextListener {
@Override
public void requestInitialized(ServletRequestEvent requestEvent) {
super.requestInitialized(requestEvent);
if (requestEvent.getServletRequest() instanceof HttpServletRequest) {
// cохраняем путь
String url = ((HttpServletRequest) requestEvent.getServletRequest()).getRequestURL().toString();
System.out.println(url);
}
}
}
<build>
<plugins>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>native</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.tn.gallery.control.Application</mainClass>
<nativeOutputDir>${app.path}/win</nativeOutputDir>
<jfxAppOutputDir>${app.path}/jfx</jfxAppOutputDir>
<verbose>true</verbose>
<appName>jGallery</appName>
</configuration>
</plugin>
</plugins>
</build>
@POST
@Path("/add")
@Produces(MediaType.APPLICATION_JSON)
public String saveNewPerson(JSONObject person) throws JSONException {
//вызов этого метода никак не влияет на код, так как toString() возвращает строку, но вы ее никак не используете
person.toString();
// тут как раз и происходит toString();
System.out.println(person + " output in service.java");
//почему в savePerson() вы кладете NULL?
if (!personDao.savePerson(null)) {
return "Person create success id=";
} else {
return "error, check information for new person";
}
}
******************************************
// Тут нужно класть Entity класс ,а не JSONObject.
session.saveOrUpdate(person);
@Entity
@Table(name = "person")
public class Person implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", nullable = false)
private int id;
@Column(name = "full_name")
private String fullName;
@Column(name = "age")
private int age;
@Column(name = "city")
private String city;
@Column(name = "gender")
@Enumerated(EnumType.STRING)
private Gender gender;
public Person(){
}
// геттеры и сеттеры обязательно
}
package application;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
/**
* @author Timur Nikiforov
*/
public class Clazz {
private Timer dateTimer;
private Timer remainderTimer;
private Date nextDate;
private boolean remainderTimerStarted;
private static final long REMINDER_UPDATE_INTERVAL = 1000;
private static final String[] DATES = { "12.04.2015 19:56", "12.04.2015 19:57", "12.04.2015 19:58" };
private int currentIndex;
public Clazz() {
dateTimer = new Timer();
}
public static void main(String[] args) {
Clazz instance = new Clazz();
instance.run();
}
private void run() {
nextDate = parseDate(DATES[currentIndex]);
schedule();
}
public void schedule() {
runSecondsCounter();
dateTimer.schedule(new TimerTask() {
@Override
public void run() {
System.out.println("Current date is:" + new Date());
currentIndex++;
if (currentIndex < DATES.length) {
nextDate = parseDate(DATES[currentIndex]);
System.out.println("Next date is:" + nextDate);
schedule();
} else {
remainderTimer.cancel();
}
}
}, nextDate);
}
private Date parseDate(String nextDate) {
Date date = null;
DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm",
Locale.ENGLISH);
try {
date = format.parse(nextDate);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
private void runSecondsCounter() {
if (remainderTimerStarted) {
remainderTimer.cancel();
}
remainderTimer = new Timer();
remainderTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
remainderTimerStarted = true;
long remains = nextDate.getTime() - new Date().getTime();
System.out.println("Remains: " + (remains / 1000) + " seconds");
}
}, REMINDER_UPDATE_INTERVAL, REMINDER_UPDATE_INTERVAL);
}
}
<dependency>
<artifactId>GWT-jQuery</artifactId>
<groupId>com.xedge.jquery.ui</groupId>
<scope>system</scope>
<version>1.1</version>
<systemPath>${basedir}/lib/gwt-jquery1.1.jar</systemPath>
</dependency>