• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

How to pass data form jsp to servlet

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps it would help if you let us know what the errors were?
 
Ranch Hand
Posts: 153
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the error:

Thank you!
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I will try to figure out and I will let you know! Thank you.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ya try what Stefan has suggested . Like below


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



- Chetan
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic