Вот мой файл Struts, в котором я сопоставил все файлы действий
struts.xml
Код: Выделить всё
/success.jsp
/error.jsp
/displayTask.jsp
/error.jsp
/displayTask.jsp
/error.jsp
AddTaskAction.java< /p>
Код: Выделить всё
package actions;
import org.hibernate.Session;
import org.hibernate.Transaction;
import com.opensymphony.xwork2.ActionSupport;
import helper.FactoryProvider;
import model.Task;
public class AddTaskAction extends ActionSupport {
private Task t = new Task();
public String post() {
Session session = FactoryProvider.getFactory().openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.persist(t);
tx.commit();
addActionMessage("Task added successfully!");
return SUCCESS;
} catch (Exception e) {
if (tx != null && tx.isActive()) {
tx.rollback();
}
addActionError("Error adding task: " + e.getMessage());
return ERROR;
} finally {
session.close();
}
}
public Task getT() {
return t;
}
public void setT(Task t) {
this.t = t;
}
}
In this below jsp page i written a code to take the data from the user and it will redirect the data into my action file to insert into databse
Код: Выделить всё
Add Task
Task Name
Description
Due Date
Priority Level
Status
ADD
Источник: https://stackoverflow.com/questions/781 ... ons-addtas