Hi Guys,
I want to get URL parameters values from servlet on pageload. I am able to call my servlet class name "UrlParamServlet" on click on button but getting null value....
I have written code like :
Servelet Code :
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
urlParameters(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
urlParameters(request, response);
}
private void urlParameters(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException {
System.out.println("In On load context path"+request.getContextPath());
System.out.println("In On load getRequestURI "+request.getRequestURI());
System.out.println("In On load getRequestURL "+request.getRequestURL());
System.out.println("In On load getServletPath "+request.getServletPath());
System.out.println("****************************Parameters*********************");
Enumeration en = request.getParameterNames();
while (en.hasMoreElements()) {
String paramName = (String) en.nextElement();
System.out.println(paramName + " = " + request.getParameter(paramName) + "<br/>");
}
if (request.getParameter("username")!=null){
System.out.println("***************************IDS GOT HERE IS:"+request.getParameter("username"));
}
FacesContext fctx = FacesContext.getCurrentInstance();
String userName = request.getParameter("username");
System.out.println("URL Parameter user Name----"+userName);
}
And Java Bean Code like :
| public String callServlets() { |
| // Add event code here... |
| |
| |
| FacesContext context = FacesContext.getCurrentInstance(); |
| try { |
| |
| HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); |
| HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse(); |
| RequestDispatcher dispatcher = request.getRequestDispatcher("/UrlParamServlet"); |
| dispatcher.forward(request, response); |
| |
| |
| }catch (Exception e) { |
| e.printStackTrace(); |
| } finally{ |
| context.responseComplete(); |
| } |
| |
| return null; |
| } |
But i am getting null values ......My output is comming Like below :
In On load context path/DemoApp-ViewController-context-root
In On load getRequestURI /DemoApp-ViewController-context-root/UrlParamServlet
In On load getRequestURL http://127.0.0.1:7101/DemoApp-ViewController-context-root/UrlParamServlet
In On load getServletPath /UrlParamServlet
****************************Parameters*********************
org.apache.myfaces.trinidad.faces.FORM = f1<br/>
javax.faces.ViewState = !lr7b5tfnt<br/>
event = cb11<br/>
_adf.ctrl-state = lxyemaken_9<br/>
event.cb11 = <m xmlns="http://oracle.com/richClient/comm"><k v="type"><s>action</s></k></m><br/>
URL Parameter user Name--------null
----------------------------------------------------------------------------------------------
UrlParamServlet is my servlet class name. Can any one suggest me how to get URL parameter values .........????
My Full URL -----> http://127.0.0.1:7101/DemoApp-ViewController-context-root/faces/Main.jspx?username=Sahdeep and i want paramete "username" value on pageload.