我正在尝试有条件地设置元素的 css。这是jsp中的行:
<s:textfield name="registerBean.email" placeholder="Email Address*" cssClass="INSERT userNameError here" required="" />
<s:textfield name="registerBean.userName" placeholder="Username*" cssClass="INSERT emailError here" required="" />
在我的动作课中,我有这样的事情:
package actions;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import service.implementations.UserServiceImplementation;
import service.interfaces.UserService;
import util.REGISTER_RESULT;
import com.opensymphony.xwork2.ActionSupport;
import entities.User;
public class Register extends ActionSupport {
private User registerBean;
private String userNameError = "register";
private String emailError = "register";
@Override
public String execute()
{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("ExamModulePu");
EntityManager em = emf.createEntityManager();
UserService service = new UserServiceImplementation(em);
REGISTER_RESULT result = service.registerUser(registerBean);
if(result.isDuplicateEmail())
setEmailError("register error");
if(result.isDuplicateUserName())
setUserNameError("register error");
em.close();
emf.close();
return result.toString();
}
public User getRegisterBean() {
return registerBean;
}
public void setRegisterBean(User registerBean) {
this.registerBean = registerBean;
}
public String getEmailError() {
return emailError;
}
public void setEmailError(String emailError) {
this.emailError = emailError;
}
public String getUserNameError() {
return userNameError;
}
public void setUserNameError(String userNameError) {
this.userNameError = userNameError;
}
}
我怎样才能使这些变量对 jsp 可用?还是有更好的方法来完成我想做的事情?