servlets

How to request.getParameterNames into List of strings?

拟墨画扇 提交于 2021-02-06 15:20:31
问题 Is it possible to get request.getParameterNames() as a list of Strings? I need to have it in this form. 回答1: Just construct a new ArrayList wrapping the keyset of the request parameter map. List<String> parameterNames = new ArrayList<String>(request.getParameterMap().keySet()); // ... I only wonder how it's useful to have it as List<String> . A Set<String> would make much more sense as parameter names are supposed to be unique (a List can contain duplicate elements). A Set<String> is also

How to update session attribute

依然范特西╮ 提交于 2021-02-06 12:50:12
问题 I have some session attributes being saved. I have a jsp page on which a call to a servlet is made through. This servlet updates one of the session variable but I am not able to see the reflection of these changes in my jsp.Pls help. In My servlet List<DriverList> abc = dao.getABC(); request.getSession().removeAttribute("abc"); request.getSession().setAttribute("abc", abc); In my jsp function update() { var url = "updateServlet"; var req = $.ajax({ type: 'GET', url: url, cache: false, type:

How to update session attribute

久未见 提交于 2021-02-06 12:48:26
问题 I have some session attributes being saved. I have a jsp page on which a call to a servlet is made through. This servlet updates one of the session variable but I am not able to see the reflection of these changes in my jsp.Pls help. In My servlet List<DriverList> abc = dao.getABC(); request.getSession().removeAttribute("abc"); request.getSession().setAttribute("abc", abc); In my jsp function update() { var url = "updateServlet"; var req = $.ajax({ type: 'GET', url: url, cache: false, type:

Sessions in Java

徘徊边缘 提交于 2021-02-05 09:32:09
问题 I have a ShoppingCart class, that contains CartItems (in an ArrayList). What I want is that whenever a session exists (when user has added items to a cart), it should request for the previous session and display it on the ViewCart jsp page. the existing code i have is giving me a lot of trouble, so i want a clear concept of how it should be done. being a c# coder, i think my logic is wrong in java. this was my c# code public class ShoppingCart { #region ListCart public List<CartItem> Items {

Why I can't use <jsp:getProperty> without <jsp:useBean>?

白昼怎懂夜的黑 提交于 2021-02-05 07:25:29
问题 Say there is servlet that has code: protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { foo.Person p = new foo.Person("Evan"); req.setAttribute("person", p); RequestDispatcher view = req.getRequestDispatcher("/result.jsp"); view.forward(req, resp); } , that goes to result.jsp to print given name (Evan). Here is a picture of how it would look (source Head First Servlets and JSP): I know that <jsp:useBean> returns same Person object by

Delete a table row by an ID which is inside hidden field

余生颓废 提交于 2021-02-05 06:53:04
问题 I have a table which generates its rows in a while loop as follows in JSP, (I use a hidden field in each row to get the specific ID and POST it to the servlet) <tr> <td><center><% out.print(rs1.getString("teamid"));%></center><input name="tid" type="hidden" value="<%out.print(rs1.getString("teamid"));%>"/></td> <td><center><% out.print(rs1.getString("teamname"));%></center></td> <td><center><% out.print(rs1.getString("teaminitials"));%></center></td> <td><center><% out.print(rs1.getString(

How to debug “java.lang.NumberFormatException: For input string: X” in Java?

被刻印的时光 ゝ 提交于 2021-02-05 06:22:07
问题 I am trying to run one program. I am really very new on Java. When I run my program I am getting following exception: Description: The server encountered an internal error () that prevented it from fulfilling this request. Exception: java.lang.NumberFormatException: For input string: "" java.lang.NumberFormatException.forInputString(Unknown Source) java.lang.Integer.parseInt(Unknown Source) java.lang.Integer.parseInt(Unknown Source) UpdateSearchRecord.doPost(UpdateSearchRecord.java:56) javax

How to debug “java.lang.NumberFormatException: For input string: X” in Java?

旧城冷巷雨未停 提交于 2021-02-05 06:21:32
问题 I am trying to run one program. I am really very new on Java. When I run my program I am getting following exception: Description: The server encountered an internal error () that prevented it from fulfilling this request. Exception: java.lang.NumberFormatException: For input string: "" java.lang.NumberFormatException.forInputString(Unknown Source) java.lang.Integer.parseInt(Unknown Source) java.lang.Integer.parseInt(Unknown Source) UpdateSearchRecord.doPost(UpdateSearchRecord.java:56) javax

How to insert the dynamic added row values into the database using JDBC Servlets

夙愿已清 提交于 2021-02-04 21:40:37
问题 Here is my jsp code, am adding and deleting the rows dynamically using javascript,but while inserting the details into the database mysql,it will insert only 1 row..How to add the dynamically added row values into the database using servlets.. Here is my code <html> <head> <title> Timeline Sheet</title> <SCRIPT language="javascript"> $('form').change(function(){ $('form').submit(); }); function validLogin(){ if (document.form.eid.value == ""){ alert ( "Please enter Employee Id." ); document

How to create the Mongo database connection in context.xml in Java web project?

﹥>﹥吖頭↗ 提交于 2021-01-29 22:31:10
问题 Although there are many proper tutorials to show how to connect relational database in Java, I really in doubt with the MongoDB mechanism working with Java. Normally people would create a connection in context.xml to interact with a relational database with JSP/servlet to do web project. However, with NoSQL database, I don't quite get any resources on how to perform this connection in a nice constructed way rather than many resources with framework lately and working seamlessly. If any