TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Get Information About Server in Servlet
SHUBHAM SHARMA
Sep 29, 2019
3.5
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
Server port number, Server Name, Protocol or parameter name or value of client side.
The Body of Index.jsp page
< form action = servlet / First_Servlet method =
"post"
> < br > First_Name < input type =
"text"
name =
"user_name"
> < input type =
"submit"
value =
"Submit"
> < /form><br></body >
First_Servlet
import
javax.servlet.*;
import
java.util.Enumeration;
import
java.io.IOException;
public
class
First_Servlet
implements
Servlet {
public
void
destroy() {}
public
ServletConfig getServletConfig() {
return
null
;
}
public
String getServletInfo() {
return
null
;
}
public
void
init(ServletConfig config)
throws
ServletException {}
public
void
service(ServletRequest req, ServletResponse res)
throws
ServletException, IOException {
System.out.println(
"server_port_Number++++++++++++++++++++++++++++++++++++++++++++++++++++"
+ req.getServerPort());
System.out.println(
"Server_Name"
+ req.getServerName());
System.out.println(
"Protocol"
+ req.getProtocol());
System.out.println(
"charcter encoding"
+ req.getCharacterEncoding());
Enumeration parameter = req.getParameterNames();
while
(parameter.hasMoreElements()) {
String parameter_name = (String) parameter.nextElement();
System.out.println(
"parameter_name"
+ parameter_name);
System.out.println(
"parameter_value"
+ req.getParameter(parameter_name));
}
Enumeration attributes = req.getAttributeNames();
while
(attributes.hasMoreElements()) {
String attribute = (String) attributes.nextElement();
System.out.println(
"parameter_name"
+ attribute);
System.out.println(
"parameter_value"
+ req.getParameter(attribute));
}
}
Get information About Server in servlet
Next Recommended Reading
Servlet Chaining using request dispatcher