小编a k*_*a k的帖子

这个表达式语言$ {pageContext.request.contextPath}在JSP EL中的作用是什么?

我有一个网络应用程序,我有不同的导航锚标签,如家庭,个人资料等.

我想要的是:

当我按下主页或个人资料等锚标签时.我只想确保当前用户在Tags/JSP页面中获取其信息.

我正在尝试的示例示例:

<a  href="${pageContext.request.contextPath}/JSPAddress.jsp">Profile</a>
Run Code Online (Sandbox Code Playgroud)

java jsp el

37
推荐指数
2
解决办法
15万
查看次数

会话属性访问并转换为int?

我在Servlet中使用以下命令在Session中存储了用户ID:

HttpSession session = request.getSession();
session.setAttribute("user", user.getId());
Run Code Online (Sandbox Code Playgroud)

现在,我想从另一个Servlet访问该用户ID:

HttpSession session = request.getSession(false);
int userid = (int) session.getAttribute("user"); // This is not working

OR

User user = new User();
user.setId(session.getAttribute("user")); This ain't possible (Object != int)
Run Code Online (Sandbox Code Playgroud)

题:

  1. 如何转换为int并将id发送到DAO以获取SELECT语句

java session servlets casting

9
推荐指数
1
解决办法
6万
查看次数

java.io.IOException:Stream已关闭

对于多个图像检索,我PhotoHelperServlet使用锚标记调用a 来获取imageNames(多个图像),如下所示

PhotoHelperServlet 得到的名字 Images

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// Getting userid from session

Image image = new Image();
image.setUserid(userid);

ImageDAO imageDAO = new ImageDAO();

try {

    List<Image> imageId = imageDAO.listNames(image);

    if (imageId == null) { 
        // check if imageId is retreived
    }

    request.setAttribute("imageId", imageId);

    //Redirect it to home page
    RequestDispatcher rd = request.getRequestDispatcher("/webplugin/jsp/profile/photos.jsp");
    rd.forward(request, response);

catch (Exception e) {
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

在ImageDAO listNames()方法中:

public List<Image> listNames(Image image) throws IllegalArgumentException, SQLException, ClassNotFoundException …
Run Code Online (Sandbox Code Playgroud)

java servlets jdbc ioexception

9
推荐指数
1
解决办法
4万
查看次数

Apache Commons Validator 帮助下的 NoClassDefFoundError 问题

如果使用 Apache Commons Validator 会出现错误:

java.lang.NoClassDefFoundError: org/apache/oro/text/perl/Perl5Util

即使 Apache Commons Validator /dependencies 声明 ORO.jar 是可选的。

java noclassdeffounderror

5
推荐指数
1
解决办法
8154
查看次数

使用JSTL在Select标签中填充的选定项目?

我使用JSP中的以下代码将生日月份存储在数据库中作为值.

<select name="birthday_month" id="birthday_month">
  <option value="-1">Month</option>
  <option value="1">Jan</option>
  <option value="2">Feb</option>
  ...
</select>
Run Code Online (Sandbox Code Playgroud)

在JSP中输出代码以使用我正在使用的JSTL显示以前选择的项目(这是不正确的)

<select name="birthday_month" id="birthday_month">
  <c:forEach var="value" items="${birthdaymonth}">
    <option value="${birthdaymonth}">${birthdaymonth}</option>
    <option value="1">Jan</option>
    <option value="2">Feb</option>
    ...
  </c:forEach>
</select>
Run Code Online (Sandbox Code Playgroud)

What I am getting from this code is value like 1 or 2 in select tag

其他信息:

  1. 我在1月,2月,3月的数据库中存储了生日月份,如1,2,3 ..
  2. 我在Servlet中使用请求范围带来生日月的值
    request.setAttribute("birthdaymonth", user.getBirthdayMonth());

我在期待什么

  1. 当我显示以后的JSP时,它应该显示先前存储的生日月份为1月,2月,3月而不是1,2,3,并且还显示其他选项值,包括突出显示的所选项目.

html java jsp jstl drop-down-menu

1
推荐指数
1
解决办法
2万
查看次数

如何从数据库中检索图像并通过Servlet在JSP中显示?

我的ImageDAO看起来像这样:

public InputStream getPhotos(Long userid) throws 
  IllegalArgumentException, SQLException, ClassNotFoundException {

  Connection connection = null;
  PreparedStatement preparedStatement = null;
  ResultSet resultset = null;
  Database database = new Database();
  InputStream binaryStream = null;

  try {

    connection = database.openConnection();
    preparedStatement = connection.prepareStatement(SQL_GET_PHOTO);                  
    preparedStatement.setLong(1, userid);
    preparedStatement.executeUpdate();

    while(resultset.next()) {
      binaryStream = resultset.getBinaryStream(4);
    }

  } catch (SQLException e) {
      throw new SQLException(e);
  } finally {
      close(connection, preparedStatement, resultset);
  }
  return binaryStream;
}
Run Code Online (Sandbox Code Playgroud)

我的ImageServlet看起来像这样:

protected void doGet(HttpServletRequest request, HttpServletResponse response) 
  throws ServletException, IOException {

  // Getting user …
Run Code Online (Sandbox Code Playgroud)

java jsp servlets image

0
推荐指数
1
解决办法
3万
查看次数