vasant

Greenhorn
+ Follow
since Apr 21, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by vasant

Hi,
Thanks for your replies.
I found some solution for my question......
requestDispatcher method satisfies my demand.
This method is available in java webserver 2.0.
Vasan
[This message has been edited by vasant (edited May 11, 2000).]
23 years ago
I'm trying to redirect the request from one server to other. Here one HTML page is getting the user name and using POST method to process that request. The corresponding server is getting the request and create the session and throws the html page
"You have hit this page 1 times."
The request is going to one server, that server is redirecting that request to another server. The redirection is working for GET method. But it is not working for POST method. The error is "Bad request and Servlet not supporting get method". How do I send(redirect) a request with parameters or how do i handle the post method?.
The code :
---------
HTML code :
<html>
<head>
<title>
</title>
</head>
<body>
<form method=POST action="http://10.2.3.101:8080/servlet/Register">
login name:<input type="text" size=20 name="lgname">
<br>
<input type="submit" value="ok">
</form>
</body>
</html>
server 10.2.3.101 has the following code: Register.java :
--------------------------------------------------------
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Register extends HttpServlet {
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws IOException, ServletException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
res.setStatus(res.SC_MOVED_TEMPORARILY);
res.setHeader("Location","http://202.41.11.100:8080/servlet/Register");
}
}

server 202.41.11.100 has the following code: Register.java :
-----------------------------------------------------------
import java.io.*;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;

public class Register extends HttpServlet {
public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
//Get the session object
HttpSession session = req.getSession(true);
// set content type and other response header fields first
res.setContentType("text/html");
// then write the data of the response
PrintWriter out = res.getWriter();
out.println("<HEAD><TITLE> " + "Registration Output " + "</TITLE></HEAD><BODY>");
String loginname = req.getParameter("lgname");
if(loginname.equals("vasan")) {
Integer ival = (Integer)
session.getValue("register.counter");
if (ival==null) ival = new Integer(1);
else ival = new Integer(ival.intValue() + 1);
session.putValue("register.counter", ival);
out.println("You have hit this page <b>" + ival + "</b>
times.<p>");
out.println("<p>");
out.println("</BODY>");
out.println("</html>");
} else {
out.println("not authorised user");
out.println("</html>");
}
out.close();
}
public String getServletInfo() {
return "A simple servlet";
}
}
[This message has been edited by vasant (edited April 21, 2000).]
[This message has been edited by vasant (edited April 21, 2000).]
23 years ago