Search code examples
javahtmljspstruts

How to get attributes from java to jsp page


create_PaperAction.java

package Actions;

import Beans.create_paperBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class create_paperAction extends org.apache.struts.action.Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        create_paperBean val = (create_paperBean)form;        
        String result = val.createDB();
        request.setAttribute("table_name", val.getTable_name());
        return mapping.findForward(result);
    }
}

I'm using struts and this is page is forwarded to createQues.jsp What i want to do is get the value of the setAttribute into an input text box on createQues.jsp. How do i do that?


Solution

  • You can get it like with Expression language.

      <input type="text" name="someX" value="${requestScope.table_name}">
    

    Other wise the same thing with scriplets(Which is not recommended)

    <%= (String) request.getAttribute ("Error_Message") %>