Passing data from java to jsp -


i working on struts , trying pass string value java file jsp page. receiving null value. please help.

my java code :

import java.io.ioexception; import javax.servlet.servletexception; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.apache.struts.action.action; import org.apache.struts.action.actionform; import org.apache.struts.action.actionforward; import org.apache.struts.action.actionmapping;  public class myaction extends action {     public actionforward execute(actionmapping mapping, actionform form,     httpservletrequest request, httpservletresponse response)     throws ioexception, servletexception {          string s="karthikeyan";          request.setattribute("s",s);          requestdispatcher reqdispatcher = getrequestdispatcher("first.jsp");         reqdispatcher.forward(request,response);                  return (mapping.findforward("success"));     } } 

my jsp code :

<%@page contenttype="text/html" pageencoding="utf-8"%>  <!doctype html> <html>     <head>         <meta http-equiv="content-type" content="text/html; charset=utf-8">     </head>      <body>         welcome!!!!!!!!          <%             string s=(string)request.getattribute("s");             out.println("s="+s);         %>     </body> </html> 

my jsp output :

welcome!!!!!!!! s=null  

i wanted know why 's' not getting assigned. appreciated.

instead of doing

<%    string s=(string)request.getattribute("s");    out.println("s="+s); %> 

try replace whole thing with:

s=${s} 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -