Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

error message

 
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i was trying code in servlet (a simple one as i m beginner)but getting error

i can see the form...but after clicking submit button i get following message



type Status report

message /WebApplication1/newhtml

description The requested resource (/WebApplication1/newhtml) is not available.
Apache Tomcat/6.0.26
 
Sheriff
Posts: 67636
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
That means that the action of the form is not the correct URL for the servlet.
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Trupti brane wrote:
message /WebApplication1/newhtml

description The requested resource (/WebApplication1/newhtml) is not available.
Apache Tomcat/6.0.26



Please cross check the <url-pattern> in web.xml and the URL you are hitting when you submit.
If you are unable to sort it out post your code here.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and Welcome to JavaRanch
 
Ranch Hand
Posts: 50
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post your code (JSP, Serlvet, web.xml) here. We then do analysis together to solve your problem.
 
Trupti brane
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
newhtml.html

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8080/WebApplication1/newhtml1" method="post">
<table style="height: 173px;width: 242px">
<tr>
<td>Last Name:</td>
<td><input type="text" name="Last_Name" size="15"></td>
</tr>

<tr>
<td>First Name:</td>
<td><input type="text" name="First_Name" size="15"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit" >
</form>
</body>
</html>

newservlet.java

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class NewServlet1 extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String Last_Name = request.getParameter("Last_Name");
String First_Name=request.getParameter("First_Name");



out.println("<html>");
out.println("<head>");
out.println("<title>Form 1</title>");
out.println("</head>");
out.println("<body>");
out.println("<table>");
out.println("<th>DETAILS</th>");
out.println("<tr>");
out.println("<td>Last Name:</td>");
out.println("<td>"+Last_Name+"</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td>First Name:</td>");
out.println("<td>"+First_Name+"</td>");
out.println("</tr>");
out.println("</table>");
out.println("<h1>Servlet NewServlet1 at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

public String getServletInfo() {
return "Short description";
}

}
 
Trupti brane
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i m not getting any error while building and running the code...is there any version problem??

i m using IDE netbins 6.9.1

also i tried code with both tomcat and glass fish server

as i m getting error after i click on submit button even i m thinking it is on action command url.

Trupti brane wrote:newhtml.html

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8080/WebApplication1/newhtml1" method="post">
<table style="height: 173px;width: 242px">
<tr>
<td>Last Name:</td>
<td><input type="text" name="Last_Name" size="15"></td>
</tr>

<tr>
<td>First Name:</td>
<td><input type="text" name="First_Name" size="15"></td>
</tr>
</table>
<input type="submit" name="submit" value="submit" >
</form>
</body>
</html>

newservlet.java

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class NewServlet1 extends HttpServlet {


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
String Last_Name = request.getParameter("Last_Name");
String First_Name=request.getParameter("First_Name");



out.println("<html>");
out.println("<head>");
out.println("<title>Form 1</title>");
out.println("</head>");
out.println("<body>");
out.println("<table>");
out.println("<th>DETAILS</th>");
out.println("<tr>");
out.println("<td>Last Name:</td>");
out.println("<td>"+Last_Name+"</td>");
out.println("</tr>");
out.println("<tr>");
out.println("<td>First Name:</td>");
out.println("<td>"+First_Name+"</td>");
out.println("</tr>");
out.println("</table>");
out.println("<h1>Servlet NewServlet1 at " + request.getContextPath () + "</h1>");
out.println("</body>");
out.println("</html>");
} finally {
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

public String getServletInfo() {
return "Short description";
}

}

 
Nam Ha
Ranch Hand
Posts: 50
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Trupti brane,

Please post your web.xml also.

Did you match the URL with the servlet?

Your form's action points to http://localhost:8080/WebApplication1/newhtml1



If you want the NewServlet1 will get invoked when hitting Submit button, you need to define a mapping in your web.xml. Please post it here.
 
Trupti brane
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Nam Ha can you tell me what is web.xml??? i do not come across such file.
 
Nam Ha
Ranch Hand
Posts: 50
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Trupti brane wrote:@Nam Ha can you tell me what is web.xml??? i do not come across such file.



web.xml is configuration file for your web application. It is located under /WEB-INF folder of your application.


Take a look here
 
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try writing this in your HTML file <form action="NewServlet1" method="post"> and execute your code instead of your <form> tag
 
Trupti brane
Greenhorn
Posts: 20
Windows Vista C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANK YOU SO MUCH @Rameshwar Soni getting output as follows


DETAILS
Last Name: rafael
First Name: nadal


that means in form action i have to always give servlet name to which it belongs???
 
Rameshwar Soni
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you are right
 
WARNING! Do not activate jet boots indoors or you will see a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic