Java 新的操作值将被放置在valuestack中,因此您必须将用户注册表保存到。要进行检查,只需将struts.xml编辑为/index.jsp/jsp/register/register.jsp,并让我们知道结果 public class UserRegist

Java 新的操作值将被放置在valuestack中,因此您必须将用户注册表保存到。要进行检查,只需将struts.xml编辑为/index.jsp/jsp/register/register.jsp,并让我们知道结果 public class UserRegist,java,jsp,struts2,Java,Jsp,Struts2,新的操作值将被放置在valuestack中,因此您必须将用户注册表保存到。要进行检查,只需将struts.xml编辑为/index.jsp/jsp/register/register.jsp,并让我们知道结果 public class UserRegistrationAction extends ActionSupport { private UserRegisterInterface userRegisterInterface = new UserRegisterService();

新的操作值将被放置在valuestack中,因此您必须将
用户注册表保存到
。要进行检查,只需将struts.xml编辑为
/index.jsp/jsp/register/register.jsp
,并让我们知道结果
public class UserRegistrationAction extends ActionSupport {
    private UserRegisterInterface userRegisterInterface = new UserRegisterService();
    public UserRegisterTO userRegisterTO = null;
    public String registerUser() {
        userRegisterTO = new UserRegisterTO(); 
        this.userRegisterTO = this.userRegisterInterface.listCountryName();
        System.out.println("The size of the list is -  ------ = "+userRegisterTO.getCountryList().size());
        return SUCCESS;
    }
<s:form action="/admin/test">
    <s:textfield label="Please enter your name" name="name"/>
    <s:submit/>
    <s:select list="userRegisterTO.countryList" 
        listkey="id" 
        listvalue="countryName"/>
</s:form>
public class UserRegisterTO 
{ 
  public List<Country> countryList = new ArrayList<Country>(); 
  public List<Country> getCountryList() 
  { 
   return countryList; 
   } 
  public void setCountryList(List<Country> countryList) { 
    this.countryList = countryList;
   } 
/**
 * 
 */
package com.castle.user.register.action;
import com.castle.user.register.service.UserRegisterInterface;
import com.castle.user.register.service.UserRegisterService;
import com.castle.user.register.service.UserRegisterTO;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Rahul
 *
 */
public class UserRegistrationAction extends ActionSupport {

    private UserRegisterInterface userRegisterInterface = new UserRegisterService();
    private UserRegisterTO userRegisterTO = null;
    public String registerUser(){
         //userRegisterTO = new UserRegisterTO(); 
        this.userRegisterTO = this.userRegisterInterface.listCountryName();
        System.out.println("The size of the list is -  ------ = "+userRegisterTO.getCountryList().size());
        return SUCCESS;
    }
    public UserRegisterTO getUserRegisterTO() {
        return userRegisterTO;
    }
    public void setUserRegisterTO(UserRegisterTO userRegisterTO) {
        this.userRegisterTO = userRegisterTO;
    }


}
/**
 * 
 */
package com.castle.user.register.service;

import java.util.List;

import com.castle.model.Country;
import com.castle.user.dao.UserRegisterDAO;
import com.castle.user.dao.UserRegisterDAOInterface;

/**
 * @author Rahul
 *
 */
public class UserRegisterService implements UserRegisterInterface{

    private UserRegisterDAOInterface userRegisterDAOInterface = new UserRegisterDAO();

    @Override
    public UserRegisterTO listCountryName() {
        List<Country> countryList = null;
        UserRegisterTO userRegisterTO = new UserRegisterTO();
        try{
            countryList = this.userRegisterDAOInterface.countryList();
            userRegisterTO.setCountryList(countryList);
        }catch(Exception e){
            e.printStackTrace();
        }
        return userRegisterTO;
    }

}
/**
 * 
 */
package com.castle.user.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import com.castle.model.Country;

/**
 * @author Rahul
 *
 */
public class UserRegisterDAO implements UserRegisterDAOInterface {
    private EntityManagerFactory entityManagerFactory;
    private EntityManager entityManager;

    public UserRegisterDAO() {
        this.entityManagerFactory = Persistence
                .createEntityManagerFactory("blogds");
        this.entityManager = entityManagerFactory.createEntityManager();
    }

    @Override
    public List<Country> countryList() {
        List<Country> countryList = null;
        String query =null;
        Query q =null;
        try{
            query = "select c from com.castle.model.Country c";
            countryList = (List<Country>)entityManager.createQuery(query).getResultList();

        }catch(Exception e){
            e.printStackTrace();
        }
        return countryList;
    }

}
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>

<package name="user" namespace="/user/registration" extends="struts-default">
    <action name="registerUser" class="com.castle.user.register.action.UserRegistrationAction" method="registerUser">
        <result name="input">/index.jsp</result>
        <result name="success" type="redirect">/jsp/register/register.jsp</result>
    </action>
</package>

</struts>
<%@include file="/header.jsp"%>
<s:form action="/admin/test">
    <s:textfield label="Please enter your name" name="name"/>
    <s:submit/>
    <s:select list="userRegisterTO.countryList" 
        listkey="id" 
        listvalue="countryName"></s:select>

</s:form>
<%@include file="/footer.jsp"%>
getUseruserRegisterTO().getCountryList();
public class UserRegistrationAction extends ActionSupport {
  private UserRegisterInterface userRegisterInterface = new UserRegisterService();
  public UserRegisterTO userRegisterTO = null;
  public String registerUser() {
            userRegisterTO = new UserRegisterTO(); 
            this.userRegisterTO = this.userRegisterInterface.listCountryName();
            return SUCCESS;
        }

public UserRegisterTO  getUserRegisterTO(){
    return this.userRegisterTO ;
} 

//setter for userRegisterTO