• 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:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

showing attributes data input fileds

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am having problems with retreving attributes inside the form inputs this the code in my servlet:



and this the front-end code:



What is wrong with this code? how can i set the attribute "user" proporly with JSTL? Cou i think that couses the problem.
 
Ranch Hand
Posts: 100
2
Python Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use ,


for getting the value of the Attribute "user" set in the servlet.
 
M Khalid
Ranch Hand
Posts: 100
2
Python Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, you can also use EL Tags,

${param.user} or ${param["user"]}

 
ubey bey
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already used request.getParameter code it did not workt. If you look at my code you will c request.setAttribute("user", user); What i want is to show user_id on the field, thats is why i call value="<c:out value="${user.user_id}" /> in the input field for the value.
 
Rancher
Posts: 4801
50
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are forwarding to the JSP page, and then doing more stuff in the servlet after it comes back.

What do you expect that to do?

The forward should be the last thing done in the servlet, in all but very unusual circumstances (and I say that because I can't at the moment think of one).
 
ubey bey
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True, its strange yesterday i placed the forwarding on the last line but it did not workd, thats why i tryd to forward first. i think  its eclipse think, i should of cleard the server and the project before run.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Did not work" isn't terribly useful.  What exactly didn't work, including any errors etc.

When the forward is in the correct place, what are the values retrieved from the request?
What value is user_id for example?
Is that a valid id, and does the DAO find the user?

 
Sheriff
Posts: 67752
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
You should have two separate servlets: one page controller that prepares data for page display then forwards to the JSP, and a task controller that receives the form submission.

Munging them all up into a single servlet is a recipe for confusion.

Please this article for an article on properly constructing Java web apps.
 
ubey bey
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your replay, i have read article.

I dont want to open unnecessary topic for my second question. Probably this question is posted before, i don't know what to search for.
i can't figure it out to solve this problem. I have developde a layout with JSTL and TAGs, i have this Home.jsp where it calls the tag fetchContent
all the contents are calld by actions and in the fetchContent.tag i have all those actions registerd one of them is login action that call Login.jspThe problem is if user wants to see the loginsuccess page i wil have to import loginsuccess.jsp and when user logs in, the login.jsp wil not disappear and loginsucces page wil be shown, so both jsp's wil be shown at the same time. So to solve this problem i read this article at coderanch  http://www.javaranch.com/journal/200603/Journal200603.jsp#a5 . I made a separated Controller and calld PageController wich calls all other beans like this my question is: Is the PageController pattern right sollution to solve the forwarding login pages(loginsucces, login, logout) wich is in my case is LoginController.javal?  i want to know for sure before i make changes in my project becouse refactoring takes much time.

kinds regards,

ubey

 
Bear Bibeault
Sheriff
Posts: 67752
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
I'm not sure what you mean by "shows both JSPs at same time".
 
ubey bey
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what i ment is when user is logd in,  the login.jsp form page is always visible becouse <c:import> is static. To solve this problem i think i have two options one is to implement a Scriptlet code on home.jsp where fetchContent tag is calld. Other option is to map those Servlets on the web.xml and implement PageController pattern.
 
Sheriff
Posts: 28324
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you have everything backwards. When you have a login form, you should be deciding what you want to see as a result of processing that form. It might be, for example, that if the login parameters aren't valid then you want to redisplay the login form with a comment that the login parameters were wrong. And if they are valid then maybe you want to forward to some other page.

So the next step is to decide what those pages should look like. Make a rough version in HTML and make a note about what variable data you have to put into the HTML.

And then write some code which generates that HTML. Typically you'd use a JSP because they are specifically designed to generate HTML. Your servlet would set request attributes and then forward to the appropriate JSP, which would then generate the HTML, using the request attributes to fill in the variable parts. Notice also that your servlet might forward to different JSPs depending on what its processing results in. You should never have to use Javascript to fiddle with the HTML after the browser displays it -- just have the JSP generate the right HTML in the first place.

If you need to use <c:import> in one of those JSPs, then do that. But if you don't, then don't do it. You're in control of the programming, and not the other way around.
 
You know it is dark times when the trees riot. I think this tiny ad is their leader:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic