java - How do I import a class in a package into a jsp file? -


it seems have correctly imported package , class, yet reason, variable user not found. user object of type string created in class addto.

<%@ page import= "package1.addto" %>  <html>  <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title>jsp page</title>  </head>   <body>     <p> shopping cart</p>     <%= system.out.println(user.name); %>  </body> </html> 

you import class package, , not it's fields.

that being said, should add addto object request attribute in servlet, , access attribute in jsp using el. should not use scriplets in new code.

in servlet do:

request.setattribute("addto", addto); 

then in jsp, can access user property of attribute addto as:

<p> shopping cart</p> ${addto.user}  <!-- access user property of addto attribute, object of type `addto` --> 

see also:


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -