Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes Not able to run sample servlet + jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Not able to run sample servlet + jsp" Watch "Not able to run sample servlet + jsp" New topic
Author

Not able to run sample servlet + jsp

Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

Hi all I am trying to run sample servlet with jsp ,first i need to display the jsp page and then when user clicks on button the form parameters needs to be passed to the servlet which is given in jsp page using action in form tag.Below are my codes,please help me regarding this

jsp page


SampleServlet


web.xml

when i tried url http://localhost:8080/<appl-name>; then its displaying the default test.jsp page when i click on submit button its not at all responding and not giving any error,any idea what is the problem
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
You're assuming that the URL format of the HTML form action attribute and the web.xml url-pattern are identical - but they're not. The former needs to include the web app context name, whereas the latter does not. This may help: http://www.coderanch.com/how-to/java/RelativeLinks
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 950
    
  13

I think you also have a problem with the attributes of your textarea. Only form elements with a "name" attribute will be submitted for form processing, not the "id" attribute. Use Firebug to look at the parameters being sent to the server on the submit. I think you'll find that nothing is being sent.


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

thanks for your replies I just added below line of code in jsp page,then also its not able to map the action to servlet
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Vas Miriyala wrote:its not able to map the action to servlet

What does that mean? What, exactly, happens if you click the submit button? Note that the button is not of type "submit", so it won't by itself submit the form.
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 950
    
  13

A button of "type=button" doesn't do anything without Javscript watching for a click event. I think you are looking for type=submit.

Also, instead of scriptlet code use action="${pageContext.request.contextPath}/hello". You really want to learn to use JSTL and EL and avoid scriptlets.
sridhar sivaraman
Greenhorn

Joined: Mar 02, 2012
Posts: 13
just replace the tag as
<form action="hello" method="POST".......>
then
<textarea ........ name="name">
and then
<input type="submit" name="submit">
and check it...
and try to cast the parameter as
String enteredtext =(String) request.getParameter("name");
Vas Miriyala
Ranch Hand

Joined: Sep 14, 2009
Posts: 114

Thanks to every one...I really appreciate your help..Now its working Fine
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not able to run sample servlet + jsp