求救大侠 菜鸟的超级难题 jsp中如何得到用户输入地址栏的完整信息,可能是错误的信息.

fujianshijy 2007-02-08 06:47:39
tomcat
localhost_access_log.2007-02-08.txt可以记录访问者的输入信息,但是我想在jsp中如何得到,request能得到么?
如ie中输入http://localhost:8080/gatetransmit/sdsfdsfd

127.0.0.1 - - [08/Feb/2007:05:03:12 -0500] "GET /gatetransmit/sdsfdsfdHTTP/1.1" 404 436 "-" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
我要的到http://localhost:8080/gatetransmit/sdsfdsfd这个信息
有可能用户输入的是http://localhost:8080/gatetransmit/saaaa
那我要得到http://localhost:8080/gatetransmit/saaaa
String test=request.getServerName() + request.getContextPath() + request.getServletPath() ;
StringBuffer ssurl = request.getRequestURL();
用这样都得不到.
会得到tomcat出错时候默认的
http://localhost:8080/gatetransmit/index.jsp
谢谢!
菜鸟自己先顶一下,大侠们救救!
我是想分析用户输入错误信息是什么.
...全文
409 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
fujianshijy 2007-02-26
  • 打赏
  • 举报
回复
新年好,过年回来,谢谢大家!
liaohaiying 2007-02-09
  • 打赏
  • 举报
回复
在你的web.xml里加上这些,
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>


error.jsp内容如下
<%@ page isErrorPage="true" %>
<HTML>
<HEAD>
<TITLE>An Error Page Using the exception Object</TITLE>
<script language="javascript">
alert(location.href);
</script>
</HEAD>

<BODY>
<%
String test=request.getServerName() + request.getContextPath() + request.getServletPath() ;
StringBuffer ssurl = request.getRequestURL();
out.println(test);
out.println(ssurl);
out.println(request.getHeader("referer"));
%>
<H1>An Error Page Using the exception Object</H1>
An error occurred: <%= exception.getMessage() %>
</BODY>
</HTML>
fujianshijy 2007-02-09
  • 打赏
  • 举报
回复
yunxiang(无名) ( )
原来配置是:

<!--
<filter>
<filter-name>ssi</filter-name>
<filter-class>
org.apache.catalina.ssi.SSIFilter
</filter-class>
<init-param>
<param-name>contentType</param-name>
<param-value>text/x-server-parsed-html(;.*)?</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>666</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>0</param-value>
</init-param>
</filter>
-->


<!-- ==================== Built In Filter Mappings ====================== -->

<!-- The mapping for the SSI Filter -->
<!--
<filter-mapping>
<filter-name>ssi</filter-name>
<url-pattern>*.shtml</url-pattern>
</filter-mapping>
-->
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1),127.0.0.1,localhost:8080测试:http://localhost:8080/gatetransmit/index.jsp,20070208230336
按照yunxiang(无名) 的试验,不行得到如上http://localhost:8080/gatetransmit/index.jsp
而且没法正常跳转了.
<!--
<filter>
<filter-name>filterauthor</filter-name>
<filter-class>
com.xing.servlet.AuthorFilter
</filter-class>
<init-param>
<param-name>contentType</param-name>
<param-value>text/x-server-parsed-html(;.*)?</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>666</param-value>
</init-param>
<init-param>
<param-name>isVirtualWebappRelative</param-name>
<param-value>0</param-value>
</init-param>
</filter>
-->


<!-- ==================== Built In Filter Mappings ====================== -->

<!-- The mapping for the SSI Filter -->
<!--
<filter-mapping>
<filter-name>filterauthor</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
和如下都试过不行
<!--
<filter>
<filter-name>filterauthor</filter-name>
<filter-class>
com.xing.servlet.AuthorFilter
</filter-class>

</filter>
-->


<!-- ==================== Built In Filter Mappings ====================== -->

<!-- The mapping for the SSI Filter -->
<!--
<filter-mapping>
<filter-name>filterauthor</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
-->
fujianshijy 2007-02-09
  • 打赏
  • 举报
回复
谢谢yunxiang(无名) ( )
我先试一试,要是好使马上结帖子,多谢up的兄弟们谢谢!
yunxiang 2007-02-09
  • 打赏
  • 举报
回复
可以实现。。
需要加过滤器。
----------
web,xml文件加上下面信息

<filter>
<filter-name>filterauthor</filter-name>
<filter-class>com.xing.servlet.AuthorFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>filterauthor</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

---------------------
这样所有的请求都会先到你加的这个过滤器里面。

过滤器里面可以通过req.getRequestURI()来得到你的连接请求。

--------
具体过滤器用法。你上网找找把。资料很多。我讲的不清楚。
zzxiaoma 2007-02-09
  • 打赏
  • 举报
回复
关注
java_new_comer 2007-02-09
  • 打赏
  • 举报
回复
function sslCheck(){
var url=location.href; //得到当前的地址栏的地址。

}
fujianshijy 2007-02-09
  • 打赏
  • 举报
回复
谢谢liaohaiying(大菜)
没有这个文件,主要是要想知道用户输入的信息是什么
没有文件是tomcat配置出错后自动转到index.jsp.
关键我是需要知道访问者在浏览器上地址栏上输入的是什么,能得到么?
谢谢关注!
yunxiang 2007-02-09
  • 打赏
  • 举报
回复
public final class AuthorFilter implements Filter {
private FilterConfig filterConfig = null;
private static final String CONTENT_TYPE = "text/html; charset=GB2312";
public void init(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest) request;
chain.doFilter(request, response);//这句话就是。安你之前的连接跳转。

}
}
liaohaiying 2007-02-08
  • 打赏
  • 举报
回复
http://localhost:8080/gatetransmit/sdsfdsfd
你这样不行的,你的gatetransmit下有sdsfdsfd这个文件吗

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧