当前位置: 代码迷 >> Java Web开发 >> servlet的路径出有关问题看 求解
  详细解决方案

servlet的路径出有关问题看 求解

热度:471   发布时间:2016-04-17 00:27:57.0
servlet的路径出问题看 求解
lizhe.jsp的代码
<%@ page language="java" contentType="text/html; charset=GB18030"
  pageEncoding="GB18030"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
</head>
<body>
<form action="TextServle" method="post"> 
姓名:<input type="text" name="username">
<input type="submit" value="提交">
</form>
</body>
</html>



TextServle的代码
package com.lizhe;

import java.io.IOException;

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

import com.li.UserManager;

public class TextServle {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username");
UserManager lo = new UserManager();
lo.add(username);
request.getRequestDispatcher("/add_success.jsp").forward(request, response);;
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}


web.xml
的配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 <servlet>
<servlet-name>TextServle</servlet-name>
 <servlet-class>com.lizhe.TextServle</servlet-class>
 </servlet>
 <servlet-mapping>
 <servlet-name>TextServle</servlet-name>
 <url-pattern>/TextServle</url-pattern>
 </servlet-mapping>
</web-app>


输入http://localhost:8080/text0/lizhe.jsp 正常显示lizhe.jsp页面 输入名字来到http://localhost:8080/text0/TextServle
就说路径错误了 求解

------解决方案--------------------
表单路径改:
Java code
<form action="http://localhost:8080/text0/TextServle/" method="post">
------解决方案--------------------
<form action="TextServle" method="get">
------解决方案--------------------
<form action="/TextServle" method="post">
------解决方案--------------------
探讨
不行的呀 还是错误的

------解决方案--------------------
getRequestDispatcher("/add_success.jsp") 确定add_success.jsp的路径对不?》
  相关解决方案
本站暂不开放注册!
内测阶段只得通过邀请码进行注册!
 
  • 最近登录:Tue Nov 20 14:00:39 CST 2018
  • 最近登录:Tue Nov 20 14:00:39 CST 2018
  • 最近登录:Tue Nov 20 14:00:39 CST 2018
  • 最近登录:Tue Nov 20 14:00:39 CST 2018
  • 最近登录:Tue Nov 20 14:00:39 CST 2018