servlets

how to pull selected radio button in a jsp

让人想犯罪 __ 提交于 2021-02-16 20:18:19
问题 I have two radio buttons, and depending on which one is selected I want to send them to a specific jsp page. I do not know how to pull which button is selected in my java class. Here is the jsp: <form method="post" action="ttp.actions.Sale1Action.action"> <input type="radio" name="radio1" value="packages"checked> packages<br> <input type="radio" name="radio1" value="productions"> productions<br> <input type="submit" value=" next "/> </form> here is the java: public class Sale2Action

How to upload file in spring?

与世无争的帅哥 提交于 2021-02-16 14:59:41
问题 I am not able to get the file name in spring controller <form:form method="post" modelAttribute="sampleDetails" enctype="multipart/form-data"> <input type="file" name="uploadedFileName" id="fileToUpload" required="" > <input type="submit" name="import_file" value="Import File" id="" /> </form:form> Its my post method in controller @RequestMapping(method = RequestMethod.POST) public String importQuestion(@Valid @RequestParam("uploadedFileName") MultipartFile multipart, @ModelAttribute(

How execute Listener class every time i receive requests on my servlet

泪湿孤枕 提交于 2021-02-16 13:47:13
问题 When receiving requests on my servlet, i would like execute one listener class which is related with, and which contains some instructions. So i implement on myListener the interface ServletContextListener, like this: public class MyContextListener implements ServletContextListener { @Override public void contextDestroyed(ServletContextEvent arg0) { // TODO Auto-generated method stub } @Override public void contextInitialized(ServletContextEvent arg0) { System.out.println("Context Created");

Tomcat 9 casting servlets to javax.servlet.Servlet instead of jakarta.servlet.http.HttpServlet

早过忘川 提交于 2021-02-15 05:30:02
问题 I have been trying in vain to implement tomcat 9's jakarta servlet as opposed to the previous javax.servlet implementation (as its my understanding that the jakarta package is the way forward). The issue is that when I point the browser at my servlet's url I get the following error(s)... java.lang.ClassCastException: class cti.nm.web.Index cannot be cast to class javax.servlet.Servlet (cti.nm.web.Index is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader

why to use public modifier in servlet

自古美人都是妖i 提交于 2021-02-11 06:48:29
问题 I want some info to prepare the first servlet program. Can anyone let me know that why we declare the userdefined class as public in servlet as well as init() , service() and destroy() also as public. Can we use other access modifiers then which are they? Why to use only public modifiers? 回答1: We have to declare servlet class and the methods init, service and destroy as public because the server should be able to access these. This is very similar to the main method declaring with the access

why to use public modifier in servlet

纵饮孤独 提交于 2021-02-11 06:48:25
问题 I want some info to prepare the first servlet program. Can anyone let me know that why we declare the userdefined class as public in servlet as well as init() , service() and destroy() also as public. Can we use other access modifiers then which are they? Why to use only public modifiers? 回答1: We have to declare servlet class and the methods init, service and destroy as public because the server should be able to access these. This is very similar to the main method declaring with the access

AWS Elastic BeansTalk Nginx Timeout 504 Bad Gateway - Java Servlet AsyncContext

我的梦境 提交于 2021-02-11 06:18:27
问题 I have successfully ran tests of a java servlet app that runs on the base sample app provided by Amazon AWS Elastic BeansTalk. Java-Gradle-Jetty Platform. Now I can't achieve to keep the servlet connected more than 50 seconds with the client no matter what I do. Things I tried. Nginx proxy_read_timeout works! proxy_send_timeout doesn't work. Load Balancer Idle Timeout Does work.. keepalive_timeout doesn't work. I have played around with these and a few more settings so I'm getting familiar

How do you dispay the current logged in user in JSP, Java servlets

假如想象 提交于 2021-02-10 19:43:04
问题 Hi i would like to know how i can display the current users username/name on a webpage when they have logged on... i am storing their username like this request.getSession().setAttribute("currentUser", username); and wat to display their username on the jsp(web page) like this <p> welcome <% request.getSession().getAttribute("currentUser"); %></p> however it doesn't work... any tips? or a method that works 回答1: Try using an expression, instead of a scriptlet: <%= request.getSession()

Forward request to spring controller

空扰寡人 提交于 2021-02-10 16:00:50
问题 From a servlet , I am forwarding the request to a spring controller like below RequestDispatcher rd = request.getRequestDispatcher("/myController/test?reqParam=value"); rd.forward(request, response); In order to pass a parameter to the spring controller , I am passing it as request parameter in the forward URL. Is there a better way of doing this ? Instead of passing in request parameter , can I pass as a method parameter to the spring controller during forward ? 回答1: This will be called when

Getting values of checkboxes along with uploading the file

天涯浪子 提交于 2021-02-10 05:47:07
问题 I was trying to upload an image in java using commonsIO and Jar for file upload.But the problem am facing is that i am having two checkboxes on my form as follow : <div style="float:left"> <input name="Mcheckbox" type="checkbox" value="Mobile"/> Mobile </div> <div style="float:right"> <input name="Echechkbox" type="checkbox" value="Email"/> Email </div> And then browse option : Upload Image : <INPUT TYPE="file" NAME="file" value="file"></input> And in my servlet am doing something like this :