简体   繁体   中英

Java Servlet 3.0 and @webservlet

Trying to access a Servlet from a button on HTML page

//Html Page

FORM method="GET" action="/StudentDBServlet"> 

yada yada

INPUT type="submit" value="Register" name="Register">

//My Servlet

@WebServlet(name="StudentDBServlet", urlPatterns={"/StudentDBServlet"})
public class StudentDBServlet extends HttpServlet {

The servlet is located in Package com.zzz.studentregistration

When I hit the "Register" Button this is the url create

http://localhost:8080/StudentDBServlet?FirstName

but it needs to be this to work properly

http://localhost:8080/com.zzz.studentregistration/StudentDBServlet?FirstName

How or where do I add the package name to the Servlet definition? I tried adding to various parts if @WebServlet but no luck ???

Thanks

The servlet container couldn't care less about your servlets' package. Only the urlPatterns matter. Your code above should work just fine. It is not clear what (and why) do you want to achieve. You can simply write:

@WebServlet(urlPatterns={"/com.zzz.studentregistration/StudentDBServlet"})

But then the form has to point to this particular servlet:

<FORM method="GET" action="/com.zzz.studentregistration/StudentDBServlet"> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM