开发者

Jersey: Passing data to a .jsp page

I'm new to Jersey and Web app development. I've attempted to Google my problem but can't seem to find the correct answer on either Jersey's documentation or the Internet. I've got a complex data type called User. This data type contains various Strings and URI's. I'm attempting to pass a variable of this type from a java file to the jsp using the following code...

.java code

return new Viewable("/page.jsp", User);

.jsp code

<%@System.out.println(request);%>

I've tried various variations on the .jsp code that I found on mailing lis开发者_开发问答ts but they all seem to return the same error which is...

org.apache.jasper.JasperException: /page.jsp (line: 3, column: 7) Invalid directive
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:408)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:89)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:498)
org.apache.jasper.compiler.Parser.parseFileDirectives(Parser.java:1777)
org.apache.jasper.compiler.Parser.parse(Parser.java:135)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:242)
org.apache.jasper.compiler.ParserController.parseDirectives(ParserController.java:119)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:193)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:373)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:353)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:644)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:389)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Where am I going wrong?


<%@ ... %> indicates a directive in JSP. For a code snippet (scriptlet), use <% ... %>.


In java file ,you need use like this:

request.setAttribute(user);

and use in jsp.file:

request.getAttribute(user);

//you can use request/session/servletContext/application to send information from java file to jsp file.

if you just need use Class User in jsp file,you just do it like this:

<@package import="//Class User's URL"> or <jsp:useBean.../>


Try to pass values from servlet to jsp page using request.setAttribute. That being said, I would suggest create a class for User and have getter setter methods to attach the values onto the class.Then pass Class.id or Class.name or Class.'whichever field' as the parameter inside request.setAttribute you want to pass to the jsp page.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜