Servlet filter in JSP
hi all,
i am working with session and jsp, for session authentication i m using servlet filter , which work fine in IE but when i run it in WAP emulator it give null exception.
i m using xhtml which run both in IE and WAP EMulator.
i dont know y it is doing so.
infact i m pushing a class in session, and when i access this class from session in 3rd page it give this null poitner exception.
what could be reason behind it.
Allah Hafiz
Generally, the client used doesn't matter. In your case, however, it sorta does. Sessions are tracked via cookies. It your WAP client does not handle cookies then you will loose the session (regular web browsers like IE can be made to ignore cookies as well...).
To fix it, use the String url = response.encodeURL("pagetogoto.html") method for ALL your links in the application. That is, everytime you send a redirect, do something like this:
response.sendRedirect(response.encodeRedirectURL("someOtherPage.jsp"));When you create a link, use this:
<a href="<%= response.encodeURL("someOtherPage.jsp")%>">Some Other Page</a>When you have a form, use:
<form action="<%= response.encodeURL("someOtherPage.jsp")%>" ...>etc...
This adds a session tracking id to the url if (and only if) the client does not allow cookies.
Similar Messages
-
Strange behavior when using servlet filter with simple index.htm
I am new to J2EE development so please tolerate my ignorance. I have a web application that starts with a simple index.htm file. I am using a servlet filter throughout the website to check for session timeout, redirecting the user to a session expiration page if the session has timed out. When I do something as simple as loading the index.htm page in the browser, the .css file and one image file that are associated, or referenced in the file are somehow corrupted and not being rendered. How do I get the filter to ignore css and image files??? Thank you!!
The servlet filter:
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SessionTimeoutFilter implements Filter {
String[] excludedPages = {"SessionExpired.jsp","index.htm","index.jsp"};
String timeoutPage = "SessionExpired.jsp";
public void destroy() {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)) {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
//httpServletResponse.setHeader("Cache-Control","no-cache");
//httpServletResponse.setHeader("Pragma","no-cache");
//httpServletResponse.setDateHeader ("Expires", 0);
String requestPath = httpServletRequest.getRequestURI();
boolean sessionInvalid = httpServletRequest.getSession().getAttribute("loginFlag") != "loggedIn";
System.out.println(sessionInvalid);
boolean requestExcluded = false;
System.out.println(requestExcluded);
for (int i=0;i<excludedPages.length;i++){
if(requestPath.contains(excludedPages)){
requestExcluded = true;
if (sessionInvalid && !requestExcluded){
System.out.println("redirecting");
httpServletResponse.sendRedirect(timeoutPage);
// pass the request along the filter chain
chain.doFilter(request, response);
public void init(FilterConfig arg0) throws ServletException {
//System.out.println(arg0.getInitParameter("test-param"));
The index.htm file (or the relevant portion)<HTML>
<Head>
<META http-equiv="Content-Style-Type" content="text/css">
<LINK href="RTEStyleSheet.css" rel="stylesheet" type="text/css">
<TITLE>Login</TITLE>
</HEAD>
<BODY>
<FORM NAME="Login" METHOD="POST" ACTION="rte.ServletLDAP"><!-- Branding information -->
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="30%" align="left"><img src="images/top_logo_new2.gif">
</td>
<td width="37%" align="center"></td>
<td width="33%" align="right"></td>
</tr>
</table>
My web.xml entry for the filter: <filter>
<description>
Checks for a session timeout on each user request, redirects to logout if the session has expired.</description>
<display-name>
SessionTimeoutFilter</display-name>
<filter-name>SessionTimeoutFilter</filter-name>
<filter-class>SessionTimeoutFilter</filter-class>
<init-param>
<param-name>test-param</param-name>
<param-value>this is a test parameter</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SessionTimeoutFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>Hi,
Try adding CSS files and images to the excluded Pages. -
Servlet Filter - for WL 5.1 (sp10) ?
Hello All,
we use WL 5.1 (sp10), on S.O. AIX.
We want to filter some JSP pages (depending on the user), like an "Servlet Filter"
(not present in WL 5.1, only 6.1 or superior) controling the "authorization".
We know the feature "UrlAcl", but is not good for us.
We recompiled the class JspBase (in package weblogic.servlet.jsp), including the
wanted aditional feature "Filter servlet"; We tested it and it is ok and no problens
ocorred.
Now we have three questions:
1- Does exits another solution to the problem above (filtering some JSP depending
on the user)?
2- My solution is good enought ? It´s normal to recompile the "internal classes
of the weblogic" ?
3- We want to send an email direct to BEA , but we don´t find a "contact" or web-form
to send this question to BEA; Anyone has this email / information ?Hello All,
we use WL 5.1 (sp10), on S.O. AIX.
We want to filter some JSP pages (depending on the user), like an "Servlet Filter"
(not present in WL 5.1, only 6.1 or superior) controling the "authorization".
We know the feature "UrlAcl", but is not good for us.
We recompiled the class JspBase (in package weblogic.servlet.jsp), including the
wanted aditional feature "Filter servlet"; We tested it and it is ok and no problens
ocorred.
Now we have three questions:
1- Does exits another solution to the problem above (filtering some JSP depending
on the user)?
2- My solution is good enought ? It´s normal to recompile the "internal classes
of the weblogic" ?
3- We want to send an email direct to BEA , but we don´t find a "contact" or web-form
to send this question to BEA; Anyone has this email / information ? -
Hi, all
I work on a web application running on a Jboss server and i would like to filter all the http request in order to save it in a database. (i save those informations for manage web stats).
I suppose i may use servlet filter, but i don't know the operation of this
Does anyone could help me giving some example and the protocol to set up this on the server (file server configuration as web.xml)Well here is what I know. I hope it helps.....
First thing is to create a class that implements the "javax.servlet.Filter" interface. But there are also other Filter interfaces that you could use depending on what you want: Filter, FilterChain, and FilterConfig.
You have to implement the init(), destroy() and doFilter() methods (I ommitted the arguments).
But most of your work will be done in the doFilter () method. You could extract request information from one of the arguments in these method and have a datasource connection to save to your back-end.
Something like :
public void doFilter( ServletRequest request, ServletResponse responce, FilterChain chain ) throws ServletException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
backEndDelegate.saveInformation( request.getRemoteAddr(), request.getRemoteHost() );
chain.doFilter( request, responce );
}Second, you need to configure the Filter. In the web.xml file add the following tags:
<filter>
<filter-name>StatsFilter</filter-name>
<description>Logs Web Stats to the back end</description>
<filter-class>com.yourpackage.StatsFilter</filter-class>
<!-- you can also pass parameters to the StatsFilter -->
<!--
<init-param>
<param-name>some parameter</param-name>
<param-value>some parameter</param-value>
</init-param>
-->
</filter>
<filter-mapping>
<filter-name>StatsFilter</filter-name>
<filter-pattern>*.jsp</filter-pattern>
</filter-mapping>That is just a little example. You can associate a filter with a Servlet using the <filter-mapping> tags too. And you can also do filter chains, but I don't feel like going there.
I sure hope that it was helpful. If not then "RTFM" -
Manipulating SOAP message in Servlet Filter
I need to capture the client IP address and place it in the SOAP message to pass it to the underlying EJB.
I am using a servlet filter to capture the IP Address but dont really know how to get the SOAP message from the HTTPServletRequest.
Any clues ?Hello,
The easiest way to call a Web Service is to use a Client Library instead of calling the SOAP call yourself.
Can you for your project use a Web Service client stack (JAX-RPC, Axis, XFire, ...) this will create from the WSDL file a set of class and give you a very simple caller class that you can then integrate to your JSP.
I am pointing you to the OracleAS Web Service Documentation section about Web Service proxy.
And some simple how-tos that have specific tasks to create client:
- Web Servics How Tos
So you can see this specific ant target to create a WS proxy:
<oracle:genProxy wsdl="[your URL to a WSDL]"
output="${src.cli.dir}"
packageName="bottomup.client.proxy"
>
<classpath>
<pathelement path="${bld.cli.dir}"/>
<pathelement location="${ORACLE_HOME}/webservices/lib/wsa.jar"/>
</classpath>
</oracle:genProxy>
Regards
Tugdual Grall -
Sendredirect() from a servlet to a jsp page
Hi all,
From word document, I have some links like this: http://localhost:8080/Test/GetFileServlet?Name=Peter&Age=12
when I click on the link, the GetFileServlet will check for user authentication.
If i haven't logged in yet, servlet will kick me to Login.jsp (jsf) to login. I use a servlet filter to filter users.
Once logged in, the page backing bean of login.jsp (Login.java) will send me to output.jsp which is only accessable to authenitcated users.
That works great......
Here is the problem when I click on the same link again.. With that I'm expecting the Servlet to kick me straight to output.jsp of JSF
However, it keeps kicking me back to the login.jsp instead of output.jsp...
Here is my sendredirect code in servlet
resp.sendRedirect("http://10.80.54.240:8080/Test/faces/Local/output.jsp?Name=Peter&Age=12);iT'S OK..i fixed it using dispatcher
-
Weblogic.utils.NestedRuntimeException when using javax.servlet.Filter
IDE: JDev 10gR3.4 & JDev 11gR2.3
ViewController technology: JSF/ADF Faces
Example code flow:
Run page2.jsf
MyFilter intercepts request, checks for parameter on session.
If parameter not null, goto page2.jsf
Else redirect to page1.jsf
page1.jsf has a button that sets the value on the session scope after clicking.
In jdev 11gR2.3, I get an weblogic.utils.NestedRuntimeException after clicking the button on page1.jsf. This error does not occur in jdev 10gR3.5. Although the application continues to execute and proper info is displayed, I’m wondering why this occurs and also if I should be concerned. Has anyone experienced a similar issue when using javax.servlet.Filter in 11g?
MyFilter code snipet:
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) {
try {
HttpServletRequest httpRequest = (HttpServletRequest)servletRequest;
HttpServletResponse httpResponse = (HttpServletResponse)servletResponse;
String redirect = httpRequest.getContextPath() + "/faces/page1.jsf"; //only difference here is 11g uses jsf, 10g uses jsp.
String uri = httpRequest.getRequestURI().toString();
Boolean mySessionAttribute = (Boolean)httpRequest.getSession().getAttribute("MYSESSIONATTRIBUTE");
if (uri.endsWith(redirect) || mySessionAttribute != null) {
filterChain.doFilter(servletRequest, servletResponse);
} else {
httpResponse.sendRedirect(redirect);
return;
} catch (IOException e) {
e.printStackTrace();
} catch (ServletException e) {
e.printStackTrace();
page1.jsf/jsp
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<h:form id="f1">
<h:commandButton value="Submit" id="cb1" action="#{Page1Bean.clicked}" type="submit"/>
</h:form>
</f:view>page2.jsf/jsp
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<f:view xmlns:f="http://java.sun.com/jsf/core" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<af:document title="main.jsf" id="d1">
<af:form id="f1">
<af:outputText value="This is the main content" id="ot1"/>
</af:form>
</af:document>
</f:view>Page1Bean.java
public class Page1Bean {
public void clicked() {
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext externalContext = context.getExternalContext();
externalContext.getSessionMap().put("MYSESSIONATTRIBUTE", Boolean.TRUE);
try {
externalContext.redirect("/11gFilterExample-ViewController-context-root/faces/page2.jsf");
} catch (IOException e) {
e.printStackTrace();
}Full exception
weblogic.utils.NestedRuntimeException: Cannot parse POST parameters of request: '/11gFilterExample-ViewController-context-root/faces/page1.jsf'
at weblogic.servlet.internal.ServletRequestImpl$RequestParameters.mergePostParams(ServletRequestImpl.java:2144)
at weblogic.servlet.internal.ServletRequestImpl$RequestParameters.parseQueryParams(ServletRequestImpl.java:2024)
at weblogic.servlet.internal.ServletRequestImpl$RequestParameters.getQueryParams(ServletRequestImpl.java:1918)
at weblogic.servlet.internal.ServletRequestImpl$RequestParameters.getParameter(ServletRequestImpl.java:1995)
at weblogic.servlet.internal.ServletRequestImpl$RequestParameters.access$800(ServletRequestImpl.java:1817)
at weblogic.servlet.internal.ServletRequestImpl.getParameter(ServletRequestImpl.java:804)
at javax.servlet.ServletRequestWrapper.getParameter(ServletRequestWrapper.java:169)
at org.apache.myfaces.trinidadinternal.context.external.ServletRequestParameterMap.getAttribute(ServletRequestParameterMap.java:43)
at org.apache.myfaces.trinidadinternal.context.external.ServletRequestParameterMap.getAttribute(ServletRequestParameterMap.java:31)
at org.apache.myfaces.trinidadinternal.context.external.AbstractAttributeMap.get(AbstractAttributeMap.java:73)
at oracle.adfinternal.controller.state.ControllerState.getRootViewPortFromRequest(ControllerState.java:788)
at oracle.adfinternal.controller.state.AdfcContext.initialize(AdfcContext.java:185)
at oracle.adfinternal.controller.state.AdfcContext.initialize(AdfcContext.java:79)
at oracle.adfinternal.controller.application.AdfcConfigurator.beginRequest(AdfcConfigurator.java:53)
at org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl._startConfiguratorServiceRequest(GlobalConfiguratorImpl.java:562)
at org.apache.myfaces.trinidadinternal.config.GlobalConfiguratorImpl.beginRequest(GlobalConfiguratorImpl.java:212)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:174)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.security.jps.ee.http.JpsAbsFilter$1.run(JpsAbsFilter.java:119)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:442)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:103)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:171)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:71)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:139)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:168)
at weblogic.servlet.internal.PostInputStream.read(PostInputStream.java:177)
at weblogic.servlet.internal.ServletInputStreamImpl.read(ServletInputStreamImpl.java:228)
at weblogic.servlet.internal.ServletRequestImpl$RequestParameters.mergePostParams(ServletRequestImpl.java:2118)
... 39 more
<UIXEditableValue> <_isBeanValidationAvailable> A Bean Validation provider is not present, therefore bean validation is disabledI dont believe that solution pertains to my case. clicked() is invoked from standard jsf page and the adf controller is not acquired yet. i put a couple of print statements in the filter and it seems that the doFilter is called twice! This is not the case when running in 10g.
if (uri.endsWith(redirect) || mySessionAttribute != null) {
System.out.println("URI dofilter: "+uri);
filterChain.doFilter(servletRequest, servletResponse);
} else {
System.out.println("URI sendRedirect: "+uri);
httpResponse.sendRedirect(redirect);
}11g weblogic console log:
URI sendRedirect: /11gFilterExample-ViewController-context-root/faces/page2
URI dofilter: /11gFilterExample-ViewController-context-root/faces/page1.jsf
URI dofilter: /11gFilterExample-ViewController-context-root/faces/page1.jsf
10g oc4j console log:
13/01/07 15:48:13 URI sendRedirect: /10gFilterExample-ViewController-context-root/faces/page2.jsp
13/01/07 15:48:13 URI dofilter: /10gFilterExample-ViewController-context-root/faces/page1.jsp
I believe whatever thats causing this occur could be why the exception is thrown... -
Problem for getting the real path using one servlet and one jsp page
I have one tomcat machine and several virtual domains. Eahc virtual domain has one realpath in the disc.
I am using one servlet and one jsp page for using this servlet.
my purpose is to load, using the servlet , the real path for the domains (eahc domain has its path).
for this i make this:
the servlet code is this:
package utils.ticker;
import java.io.*;
import java.io.File;
import java.io.IOException;
import java.net.*;
import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class Edicion extends HttpServlet{
public Edicion() {
public String cc(){
ServletContext myContext= getServletContext();
String abspath = myContext.getRealPath("/");
//here i want to return the real path
return abspath;
public static void main(String args[]){
and the jsp page is:
<%@ page import="utils.ticker.*" %>
<jsp:useBean id="tick" class="utils.ticker.Edicion" scope="session"/>
<html><head><body>
<%
tick.cc();
%>
</body></head></html>
But this produces one error, NullPointerException and dont shows me the real path.
Can anyone help me?
thanksi have put this into one sevlet:
package utils.ticker;
import javax.servlet.ServletContext;
public class Edicion{
private ServletContext myContext;
public Edicion(ServletContext myContext) {
this.myContext = myContext;
public String getCC(){
return myContext.getRealPath("/");
and in the jsp page this:
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*"%>
<%@ page import="utils.ticker.*" %>
<jsp:useBean id="tick" class="utils.ticker.Edicion" scope="session"/>
<html><head><body>
<%=tick.getCC()%>
</body></head></html>
but appear this error in the tomcat.
Can you, please, help me. i am trying to solve this during one week and i am desesperate.
Thanks.
ERROR:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: class utils.ticker.Edicion : java.lang.InstantiationException: utils.ticker.Edicion
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:248)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:536)
root cause
javax.servlet.ServletException: class utils.ticker.Edicion : java.lang.InstantiationException: utils.ticker.Edicion
at org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:533)
at org.apache.jsp.pruebas_jsp._jspService(pruebas_jsp.java:72)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:204)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:536)
Apache Tomcat/4.1.18 -
Servlet filter is not protecting html files
Hi All,
I am using Iplanet web server 6.0 SP4 with JDK v1.3.1_06. I am able to protect the JSP page using the servlet filter. But when I try to access the html files then filter is not getting invoked. The content of web-apps.xml is given below :-
<web-app>
<filter>
<filter-name>TestIntercepto</filter-name>
<filter-class>testinterceptor</filter-class>
</filter>
<filter-mapping>
<filter-name>TestInterceptor</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Can you guys tell me the reason ?I don't know much about IPlanet but with Apache/Tomcat it is possible to configure Apache to serve static content from a web application (eg: non-JSP pages) which would mean that Tomcat was never able to intercept the request for the page in the first place. Just a though.
-
Tomcat 6 Calling a Java Servlet from a JSP Page
Below is a very simple JSP Page that calls a Java Servlet. The question is given Tomcat security constraints, is it possible to call a servlet from a JSP and get the correct output without getting an error message? If so, how would you code the web.xml file?
c:\apache-tomcat-6.0.18
Under conf
catalina
localhost
HelloWorldExample.xml is directly under localhost
The application would have this directory structure:
webapps
HelloWorldExample
hello.jsp is directly under HelloWorldExample
Under HelloWorldExample
src
WEB-INF
classes
Under classes
jservlets
HelloWorld.java is in src folder
HelloWorld.class is in jservlets folder
HelloWorldExample.xml
<Context path="/HelloWorldExample" docBase="HelloWorldExample" debug="0"
reloadable="true" crossContext="true">
</Context>**************************
hello.jsp
<HTML>
<HEAD>
<TITLE>Hello</TITLE>
</HEAD>
<BODY>
<FONT SIZE="4">
<P>
Please enter your name:
<FORM
METHOD="Post"
ACTION="servlet/jservlets.HelloWorld">
<TABLE BORDER="3" CELLPADDING="1" WIDTH="100%" ALIGN="CENTER">
<TR>
<TD><B>Name:</B></TD>
<TD><INPUT TYPE="text" NAME="Name" VALUE="" SIZE="65"> </TD>
</TR>
</TABLE>
<P>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</FONT>
</BODY>
</HTML>******************
HelloWorld.java
package jservlets;
import java.io.*;
import java.util.Date;
import java.util.*;
import java.text.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet
PrintWriter out;
PrintWriter err;
String strName;
public void displayMessage(HttpServletRequest request, HttpServletResponse response)
throws Exception
try
if (!strName.equals("") && strName != null)
out.println("Hello " + strName + "" + "<P>");
out.println("Hello World" + "<P>");
else
out.println("Hello World" + "<P>");
catch (Exception e)
out.println("Exception: Could not display message." + "<P>");
err.println (e.getMessage () ) ;
out.println("<P>");
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
try
response.setContentType("text/html");
out = response.getWriter();
err = response.getWriter();
strName = request.getParameter("Name").trim();
out.println("<html><head><title>");
out.println("</title></head><body>");
out.println("<FORM");
out.println("METHOD=POST");
out.println("ACTION=http://localhost:8080/HelloWorldExample/hello.jsp>");
out.println("<TABLE ALIGN='RIGHT'>");
out.println("<TR>");
out.println("<TD>");
out.println("<INPUT TYPE=\"SUBMIT\" VALUE=\"Hello World Page\";>");
out.println("</INPUT>");
out.println("</TD>");
out.println("</TR>");
out.println("</TABLE>");
out.println("</FORM>");
out.println("<BR CLEAR='all'>");
out.println("<P>");
displayMessage(request, response);
out.close();
out.println("</body></html>");
catch(Throwable e)
e.printStackTrace();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
doPost(request, response);
web.xml
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>jservlets.HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/servlet/HelloWorld</url-pattern>
</servlet-mapping> ******************************
HelloWorld.java can be compiled by using javac.
Once compiled, HelloWorld.class would be moved to the jservlets folder.
FYI, coding the above url-pattern results in:
HTTP Status 404
The requested resource (/HelloWorldExample/servlet/jservlets.HelloWorld) is not available
The following url-pattern in the web.xml file permits the servlet to be executed but results in a null pointer exception:
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/ </url-pattern>
</servlet-mapping> **************************************************
RobinThis problem was resolved.
In hello.jsp
ACTION="servlet/jservlets.HelloWorld">
was replaced with
ACTION="servlet/HelloWorld">
Robin -
How can I set the user's role in the request object in a servlet filter
so that in my action class, i can query the role using
request.isUserInRole() and request.getUserPrinciple() methods.
Any ideas...
Thanks,How can I set the user's role in the request object
in a servlet filter
so that in my action class, i can query the role
using
request.isUserInRole() and request.getUserPrinciple()
methods.You may want to check out JAAS in the Creator tutorial:
http://developers.sun.com/prodtech/javatools/jscreator/ea/jsc2/reference/sampleapps/ -
Hi, I have recently been having problems with embedding a servlet within a JSP. I have attempted to do this by using a frame within the JSP and using JSP include tags however, nothing seems to display. The reason why I want to do this is because I need to take advantage of servlet persistence which JSPs do not have, plus, I want to use the JSP to refresh the page produced by the servlet every so often using AJAX.
Any ideas? Thanks,
--RA JSP becomes a pure servlet on compilation. What persistence are u looking in a JSP ?
One reason you do not get anything is I am not tried this but I dont think its going to interpret the servlet code very well in the JSP page.
An include JSP tag includes another jsp/file inline and not sure if he can do a servlet there ? -
How to Include a servlet in a jsp
Hello,
My jsp pages are all tied to respective Servlets. So when I have to forward to a jsp, I forward to a servelt which redirects to that jsp.
Now I have a jsp page which has to include another jsp page.
So I am trying to include a servlet in my jsp page which inturn redirects itself to the included jsp.
Have tried doing the following
<jsp:include page="../../servlet/ServletName" flush="true">
</jsp:include>
does not work. It compiles well but no output
any ideas ????
~ SoumyaIt does not seem to work... Let me give you the snippet of code I used.
calendarEntry.java - the parent jsp
<tr rowspan="60%">
<td width="100%">
<jsp:include page="file://c:/../../servlet/MonthEventList">
</jsp:include>
</td>
</tr>
MonthEventList.java - the included servlet
import javax.servlet.*;
import javax.servlet.http.*;
public class MonthEventList extends HttpServlet {
* Attributes
private static final String CONTENT_TYPE = "text/html";
private HttpSession session;
public void init() throws ServletException
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException
try {
HttpSession session = request.getSession(true);
String url;
url = "/jsp/site/calendar/monthEventList.jsp";
//ReDirect to where the page is going
response.sendRedirect(url);
return;
} catch (Exception ex) {
String url="/jsp/site/calendar/main/servletError.jsp;
response.sendRedirect(url);
return;
public void doGet(HttpServletRequest request,HttpServletResponse
response) throws ServletException, IOException
doPost(request, response);
monthEventList.jsp
just displays some dummy data
So if this is the case, do you think the <jsp:include> can work ??
Thanks in advance
Soumya -
I've written a simple servlet filter to intercept a request to another servlet. So when the user tries to access /servlet/ViewMetadata servlet, they first hit InterceptServlet, the filter configured in Tomcat.
I need to access the name and URL of the target servlet ViewMetada within InterceptServlet but don't know how to do this. I am familiar with HttpServletRequest.getServletPath() but doFilter uses ServletRequest as its argument.
Can I obtain the target servlet name inside the filter servlet? I know this is probably very basic!
ArcIf the filter is invoked by a HttpServletRequest, then the ServletRequest handle you've in the filter is just an instance of HttpServletRequest.
Cast it back. -
How to display outsream from a servlet in a JSP
I wrote a jsp file to call a Servlet, then want to display the result from the servlet in another jsp file. Anyone can give me possible solution or an example to illustrate it.
Many thanks in advance.
the file that call servlet in a jsp is as follow
<form method="POST" action="myservlet">
<table>
<tr>
<th align="center" colspan="2">
Enter The query words
</th>
</tr>
<tr>
<th align="right">query words:</th>
<td align="left">
<input type="text" name="querywords" size="60">
</td>
</tr>
<tr>
<td align="right">
<input type="submit" value="Search">
</td>
<td align="left">
<input type="reset" value="Reset">
</td>
</tr>
</table>
</form>
............I would suggest that you use the Servlet to retrieve the data you are after and store it in the session. Then forward the user onto the JSP page where it can retrieve the object from the session and present it to the user in a formatted view.
Maybe you are looking for
-
HI ALL MY CLIENT WANT TO GET INVOICE NUMBER,GL ACCOUNT,CHQ NO FOR EACH INVOICE IN PAYMENT RUN. IS THERE ANY WAY TO GET THIS. THANKS/REGARDS MURALIDHAR
-
WebCenter Portal and Portlet support in JDeveloper 11.1.2 version
Hi, When the WebCenter Portal and Portlet application creation will be available within JDeveloper 11.1.2 version ? Thanks Eli
-
Trying to add new swatch library, I get " Cant open, select AI 8 or above or EPS"
I am trying to add the "Roland Color Systems Library.ai" into ID CS6. I added the same file with no problem to AI CS3 but when I try adding it to ID, I get: "Cannot open file, please select an Adobe Illustrator 8 or above document or EPS file, or an
-
An illegal file name cause FileUpload element timeout.
I can use Fileupload UI Element of Web Dynpro Abap to upload files with no problem. But if I type some illegal file name(like 'asdf' ) in the inputfield before the 'browser' button,and click some other button which will fire an action to refresh this
-
Hello, We have encountered a problem: We are using Windows-1250 codepage (EE8MSWIN1250) with Oracle8i 8.1.7.0. When we use correct string with special characters (from Slovak language) in CLOB, after loading it to the XML parser and retrieving it bac