JAVA错误 这是什么错误 求大神指教
错误提示java.lang.StringIndexOutOfBoundsException:Stringindexoutofrange:-8java.lang.Strin...
错误提示java.lang.StringIndexOutOfBoundsException: String index out of range: -8 java.lang.String.substring
给出一部分代码:
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//取消乱码了
//String s=new String(request.getParameter("userName").getBytes("ISO-8859-1"),"UTF-8");
//System.out.println(s);
String url = request.getRequestURI();
String action = url.substring(url.lastIndexOf("/"),url.lastIndexOf("."));
//HttpSession session1 = request.getSession();
User user=new User();
UserDao userDao= new UserDao();
DeleteUserDao deleteUserDao=new DeleteUserDao();
FindDao findDao =new FindDao();
FindByNameDao findByNameDao=new FindByNameDao();
UpdateDao updateDao=new UpdateDao();
//增加用户
if("/add".equals(action)){
//user.setId(Integer.parseInt(request.getParameter("id")));
user.setUserName(new String(request.getParameter("userName").getBytes("ISO-8859-1"),"UTF-8"));
user.setPwd(new String(request.getParameter("pwd").getBytes("iso-8859-1"),"utf-8"));
user.setAge(Integer.parseInt(request.getParameter("userAge")));
user.setSex(new String(request.getParameter("sex").getBytes("ISO-8859-1"),"UTF-8"));
user.setHobby(new String(request.getParameter("hobby").getBytes("ISO-8859-1"),"UTF-8"));
user.setEdu(new String(request.getParameter("edu").getBytes("ISO-8859-1"),"UTF-8")); 展开
给出一部分代码:
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
//取消乱码了
//String s=new String(request.getParameter("userName").getBytes("ISO-8859-1"),"UTF-8");
//System.out.println(s);
String url = request.getRequestURI();
String action = url.substring(url.lastIndexOf("/"),url.lastIndexOf("."));
//HttpSession session1 = request.getSession();
User user=new User();
UserDao userDao= new UserDao();
DeleteUserDao deleteUserDao=new DeleteUserDao();
FindDao findDao =new FindDao();
FindByNameDao findByNameDao=new FindByNameDao();
UpdateDao updateDao=new UpdateDao();
//增加用户
if("/add".equals(action)){
//user.setId(Integer.parseInt(request.getParameter("id")));
user.setUserName(new String(request.getParameter("userName").getBytes("ISO-8859-1"),"UTF-8"));
user.setPwd(new String(request.getParameter("pwd").getBytes("iso-8859-1"),"utf-8"));
user.setAge(Integer.parseInt(request.getParameter("userAge")));
user.setSex(new String(request.getParameter("sex").getBytes("ISO-8859-1"),"UTF-8"));
user.setHobby(new String(request.getParameter("hobby").getBytes("ISO-8859-1"),"UTF-8"));
user.setEdu(new String(request.getParameter("edu").getBytes("ISO-8859-1"),"UTF-8")); 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询