This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes error message Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "error message " Watch "error message " New topic
Author

error message

Trupti brane
Greenhorn

Joined: Aug 16, 2011
Posts: 20

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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60752
    
  65

That means that the action of the form is not the correct URL for the servlet.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
bhanu chowdary
Ranch Hand

Joined: Mar 09, 2010
Posts: 256
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.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

and Welcome to JavaRanch
Nam Ha
Ranch Hand

Joined: Aug 05, 2011
Posts: 50

Please post your code (JSP, Serlvet, web.xml) here. We then do analysis together to solve your problem.


Java Object Creation
Trupti brane
Greenhorn

Joined: Aug 16, 2011
Posts: 20

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

Joined: Aug 16, 2011
Posts: 20

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

Joined: Aug 05, 2011
Posts: 50

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

Joined: Aug 16, 2011
Posts: 20

@Nam Ha can you tell me what is web.xml??? i do not come across such file.
Nam Ha
Ranch Hand

Joined: Aug 05, 2011
Posts: 50

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
Rameshwar Soni
Ranch Hand

Joined: Feb 03, 2011
Posts: 247
Try writing this in your HTML file <form action="NewServlet1" method="post"> and execute your code instead of your <form> tag
Trupti brane
Greenhorn

Joined: Aug 16, 2011
Posts: 20

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

Joined: Feb 03, 2011
Posts: 247
Yes you are right
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error message
 
Similar Threads
Sending SMS through webapplication
Sending an HTTP request from behind Apache
Communication between servlets of two different applications
Problem with error-code tag
Requesting the method in the WS hangs