java servlet报HTTP/1.1 403 Forbidden错误

fdqtd3yt 2014-05-26 08:34:34
代码的主要功能是实现下拉框的二级联动,一级菜单menu,二级菜单subMenu

OptionServlet.java
package cn.com.test;


import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import cn.com.atnc.ioms.mng.systemmng.clientlog.IClientLogManager;


@SuppressWarnings("serial")
public class OptionServlet extends HttpServlet {

@Autowired
private IClientLogManager clientLogManager;

/**
* Constructor of the object.
*/
public OptionServlet() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

this.doPost(request, response);
}

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
@SuppressWarnings("unused")
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=gb2312");
request.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
String str=null;
String strId=request.getParameter("menu");
System.out.println(strId+" 1");
strId=new String(strId.getBytes("ISO-8859-1"),"GB2312");
System.out.println(strId+" 2");
if(strId==null){
return;
}else{
/*ClientLogQueryModel qm=new ClientLogQueryModel();
qm.setMenu(strId);
*/
try {
str=clientLogManager.querySubMenu(strId);
//str=optionService.selectChild(optionDTO); //调用model层类OptionService的selectChild()方法,结果是一个字符串
out.println(str); //作为返回给ajax中xmlhttp的结果
} catch (Exception e) {
//e.printStackTrace();
}
}
out.flush();
out.close();
}

/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}

}



jsp页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html;charset=utf-8"%>
<%@ include file="/WEB-INF/jsp/include.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<head>
<title>客户日志</title>
<link rel="stylesheet" type="text/css" href="${rootUrl }css/main.css" />
<link rel="stylesheet" type="text/css" href="${rootUrl }css/top_b.css" />
<link rel="stylesheet" type="text/css" href="${rootUrl }css/pager.css" />

<script src="${rootUrl }js/jquery/jquery.js" type="text/javascript"></script>
<script src="${rootUrl }js/jquery/jquery.tablesorter.js"
type="text/javascript"></script>
<script src="${rootUrl }js/jquery/jquery.pager.js"
type="text/javascript"></script>
<script src="${rootUrl }js/jquery/jquery.form.js" type="text/javascript"></script>
<script src="${rootUrl }js/jquery/jquery.manage.js"
type="text/javascript"></script>
<script src="${rootUrl }js/jquery/jquery.nyroModal.js"
type="text/javascript"></script>
<script src="${rootUrl }js/jquery/jquery.validate.js"
type="text/javascript"></script>
<script src="${rootUrl }js/jquery/jquery.metadata.js"
type="text/javascript"></script>
<script src="${rootUrl }js/datepicker/WdatePicker.js"
type="text/javascript"></script>

<script type="text/javascript">
$(function(){

$("#queryResult").manage({
pagerUrl:true,
add:true,
edit:true,
update:true,
view:true,
boxwidth:"550",
boxheight:"560"
});


});

var response;
var menu;
var subMenu;
function getOption(){
menu=document.forms["listForm"].elements["menu"];
subMenu=document.forms["listForm"].elements["subMenu"];
if(menu.selectedIndex==0){
subMenu.length=1;
return;
}
var xmlhttp;
try{
xmlhttp=new XMLHttpRequest();
}catch(e){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
alert(xmlhttp.readyState);
xmlhttp.onreadystatechange=function(){
if(4==xmlhttp.readyState){
if(200==xmlhttp.status){
response = xmlhttp.responseText;
alert(response);
show(response);
}
}
}
var index=menu.selectedIndex;
//alert(index);
var id=menu.options[index].value;
//alert(id);
var url="<%=path%>/OptionServlet?menu="+escape(id);

xmlhttp.open("get",url);

xmlhttp.send(null);

return;
}

function show(response){
alert("hh");
var a=response.length;
//alert(a);
var arr=new Array(a);
arr=response.split(",");
//alert(arr.length);
subMenu.length=1;
var k=1;
for(var j=0;j<arr.length;j+=2){
subMenu.options[k]=new Option(arr[j+1],arr[j]); //此处值得商酌
//alert(arr[j+1]+"arr[j+1]");
//alert(arr[j]+"arr[j]");
k++;
}
}

</script>



</head>
<body>
--------此处省略部分代码

一级:
<form:select path="menu" id="menu" cssStyle="width:80px"
onchange="getOption()">
<form:option value="">全部</form:option>
<c:forEach items="${menus}" var="item">
<option value="${item}">${item}</option>
</c:forEach>
<%-- <form:options items="${bureaus}" itemLabel="value" /> --%>
</form:select>
二级: <select name="subMenu" id="subMenu">
<option value="">请选择二级分类</option>
</select>

</div>
<div class="bclear"></div>

<a href="#none" class="sbtn" id="queryButton">查询</a> <a
href="#none" class="sbtn" onclick="listForm.reset();">重置</a>
</div>
<div class="bclear"></div>

</div>
</form:form>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- 内容页 -->
</div>

<!-- 版权页 -->
<%@ include file="/WEB-INF/jsp/bottom.jsp"%>
<!-- 版权页 -->
</body>
</html>


web.xml配置文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>IOMS</display-name>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<!-- Web 应用根目录以该属性名(webapp.name)添加到系统参数(System.property)中 -->
<!-- 放在web.xml的最上面,确保其最早被初始化好让${webapp.name}可以用于其他地方 -->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>ioms.name</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.WebAppRootListener
</listener-class>
</listener>
<!-- spring bean listener -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/beans/activiti.xml,/WEB-INF/beans/main.xml,/WEB-INF/beans/applicationContext-security.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 加载页面访问控制列表-->
<listener>
<listener-class> cn.com.web.load.ServletContextLoaderListener</listener-class>
</listener>
<!-- 强制编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
<url-pattern>*.dox</url-pattern>
</filter-mapping>
<!--spring -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>3</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.do</url-pattern>
<url-pattern>*.dox</url-pattern>
</servlet-mapping>
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>OptionServlet</servlet-name>
<servlet-class>cn.com.test.OptionServlet</servlet-class>
<load-on-startup>4</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>OptionServlet</servlet-name>
<url-pattern>/OptionServlet</url-pattern>
</servlet-mapping>
<!-- SpringSecurity filter-->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>



用firefox调试功能,当选择一级菜单时候,二级菜单不会变化,且报错:

请求网址:
http://localhost:8080/om/OptionServlet?menu=t1

请求方法:
GET

状态码:
HTTP/1.1 403 Forbidden


求各位大神帮下忙,谢谢了。
...全文
1204 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fdqtd3yt 2014-05-28
  • 打赏
  • 举报
回复
顶,大神们快来帮忙看看啊
tony4geek 2014-05-27
  • 打赏
  • 举报
回复
为什么没有权限,你换个浏览器试试。
fdqtd3yt 2014-05-27
  • 打赏
  • 举报
回复
没人么,自己顶

81,092

社区成员

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

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