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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -