Cus,mam mensi problem :-) mam html subor s inputom,ktory ked pustim tak ide na "http://localhost:8081/SimpleServletProject/Simaa.html" ked odoslem Name tak ma presmeruje na "http://localhost:8081/xmlServletpath?userName=as" namiesto toho aby ma to presmerovalo na "http://localhost:8081/SimpleServletProject/xmlServletpath?userName=as" .Dakujem za rady :-)
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/xmlServletpath" method="post">
<input name="userName" />
<input type="submit" />
</form>
</body>
</html>
Servlet:
package javaeetutorial;
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;
public class XmlServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
String userName=request.getParameter("userName");
PrintWriter out=response.getWriter();
out.println("Hello! "+ userName);
}
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/…-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>SimpleServletProject</display-name>
<servlet>
<servlet-name>xmlServlet</servlet-name>
<servlet-class>javaeetutorial.XmlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>xmlServlet</servlet-name>
<url-pattern>/xmlServletpath</url-pattern>
</servlet-mapping>
</web-app>
dakujem :)