简体   繁体   中英

How to use Value of an Variable of JSP page in JAVA CLASS

I know its easy to use values of form ,from jsp to java,But how to use a variable value of JSP code into java class. For eg, I want to use value of vlaue in a java class any help will be appreciated,thanx

  <%
     String value=null;
    value= (String) session.getAttribute("name");

    %>

Please be more specific. Where you need to access your request or session data?

You can get all data at you servlet code the same way as at JSP (i fact, JSPs are being compiled to servlets behind the curtain):

request.getSession().getAttribute("some");

If the data comes from a jsp/html then you should use:

request.getParameter("value")

if the data is saved in the session then get it from the session using:

req.getSession().getAttribute("value");

Then I also suggest you ensure it is not null:

String value = (String) request.getParameter("value");
if(value != null){ 
   // the value is at the form, so you can get it and use it
} 
else{
   //the value is not at the html or the value is not given a value
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM