Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to pass data form jsp to servlet

 
baxhuli pema
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I am passing data to my servlet through the jsp in this way:

So I am passing the firstName parameter from my bean class (if I am correct). Now I want to pass the firstName through the session.getAttribute("username");
So I want to do something like this:

and then

But I am getting errors when I try this. Can anyone please tell me what is my bad?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps it would help if you let us know what the errors were?
 
Karn Kumar
Ranch Hand
Posts: 153
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi baxhuli pema,


Can you describe error you are getting , so that it will be easy to find out exact mis ?

If you are getting error on the JSP then put try-catch block and all your code inside it and print Stack Trace.

Also same can be done in the servlet .


- Chetan
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chetan Dorle wrote:then put try-catch block and all your code inside it and print Stack Trace.

Not good advice -- modern JSPs should have no Java code inside them. (Even though it is clear that the OP is violating this precept.)

The best advice is for the errors to be posted so we can evaluate what is going on.

To the OP: Java code in a JSP is an obsolete practice. Please see this JspFaq entry
 
baxhuli pema
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the error:

Thank you!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's telling you right where the error is: /detyra.jsp (line: 24, column: 24)

Look at what's there.
 
baxhuli pema
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it is saying "quote symbol expected" so I understand that I can not enter in that way <%=user%>. That's why I am asking. If you know how can I do that. Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that what's at line 24?

Also remember that anything that's not a JSP mechanism is merely template text and has no meaning.

And, again, you should be using JSTL and EL rather than obsolete Java scriptlets.
 
baxhuli pema
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I will try to figure out and I will let you know! Thank you.
 
Stefan Evans
Bartender
Posts: 1721
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presuming that this is line 24:


There is an extra quote in there.
If the user was 'Bob' then what this would produce is:



There are three quotes in that line of html.
I think you should be removing the second one.

Also I would suggest you do some sort of Url Encoding if you are going to build up a URL string in this fashion.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64844
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to format a URL in a JSP is with the JSTL <c:url> tag.
 
Karn Kumar
Ranch Hand
Posts: 153
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya try what Stefan has suggested . Like below


<a href="DetyraServlet?action=listDetyra&firstName=<%=user%>">Something</a>



- Chetan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic